Customisable file field (excluding the file name)? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Customisable file field (excluding the file name)?

Post by submeg » 29 Jul 2021, 07:32

Hi all,

To organise my emails in Outlook, I use categories. I was wondering if this would be possible with files as well.

Does anyone know if there is a field / attribute of files that is common to all file types that isn't the filename?

If there isn't a separate field, I created a tool (see code below) that will allow a user to specify three individual letters to add as a prefix to the currently selected file. If my only option is to rename files, how can I loop through the currently selected files to rename all that are selected?

Code: Select all


#SingleInstance, Force

F3::

;https://autohotkey.com/board/topic/57362-retrieve-the-name-of-the-currently-selected-files/#entry360328
clipboard =

Send, ^c
Clipwait, 3
FullPath := clipboard

;MsgBox, % "FullPath: " FullPath

;https://autohotkey.com/board/topic/98215-get-the-file-extension/#entry618424
StringGetPos, PosA, FullPath, ., R
StringRight, CurrentExt, FullPath, % StrLen(FullPath)-PosA	;-1
   
;MsgBox, % "CurrentExt: " CurrentExt

clipboard =

Send, {F2}
Sleep, 25

Send, ^c
Clipwait, 3
FilePath := clipboard

;MsgBox, % "Filepath: " FilePath

ParentPath := SubStr(FullPath,1, StrLen(FullPath)-( StrLen(FilePath) + StrLen(CurrentExt) ))

;MsgBox, % "ParentPath: " ParentPath

clipboard =

;-------------------------------------------------------------

Gui, FileRename:New, +AlwaysOnTop +ToolWindow +Resize

Gui, Add, Text, x10, Prefix 1:
Gui, Add, Edit, x+5 w50 vPF1

Gui, Add, Text, x10 y+10, Prefix 2:
Gui, Add, Edit, x+5 w50 vPF2

Gui, Add, Text, x10 y+10, Prefix 3:
Gui, Add, Edit, x+5 w50 vPF3

Gui, Add, Button, x150 y+17 w225 h40 gAddPrefix, `r Add Prefix

Gui, FileRename:Show, w420 h300, - FileSort - 

Return 

;-------------------------------------------------------------

AddPrefix:

;Gui, Submit, NoHide

GuiControlGet, PF1
GuiControlGet, PF2
GuiControlGet, PF3

FilePrefix := PF1 . PF2 . PF3 . "_"

;msgbox % "The prefix is: " FilePrefix
;msgbox % "New full path: " ParentPath . FilePrefix . FilePath . CurrentExt

NewFullPath := ParentPath . FilePrefix . FilePath . CurrentExt

FileMove, %FullPath%, %NewFullPath% 

if (ErrorLevel)
msgbox Error; can't rename file.

Return

;-------------------------------------------------------------

____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Customisable file field (excluding the file name)?

Post by mikeyww » 29 Jul 2021, 08:26

You could use @teadrinker's Explorer_GetSelection, and then use FileMove as you loop through the results.

Total Commander implements an interesting feature for creating file descriptions. It creates a plain text file that stores the information. Tags can be added. This method could be used as an alternative to renaming the file, though it might require handling when the file is renamed, moved, copied, etc.

User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: Customisable file field (excluding the file name)?

Post by submeg » 29 Jul 2021, 16:24

mikeyww wrote:
29 Jul 2021, 08:26
You could use @teadrinker's Explorer_GetSelection, and then use FileMove as you loop through the results.
Nice, thanks @mikeyww, I will try that this afternoon.
mikeyww wrote:
29 Jul 2021, 08:26
Total Commander implements an interesting feature for creating file descriptions. It creates a plain text file that stores the information. Tags can be added. This method could be used as an alternative to renaming the file, though it might require handling when the file is renamed, moved, copied, etc.
Have you used this before? Does this override Windows' standard file handling process, or work in tandem with it?
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Customisable file field (excluding the file name)?

Post by mikeyww » 29 Jul 2021, 16:34

Total Commander does not override anything. It just manages a text file that can be updated through a user interface managed by the program. It does handle the files properly when files are renamed, copied, or moved. I guess you could say that it works in tandem with Windows.

User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: Customisable file field (excluding the file name)?

Post by submeg » 29 Jul 2021, 16:37

It just manages a text file that can be updated through a user interface managed by the program.
And that file remembers the different attributes of files?
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Customisable file field (excluding the file name)?

Post by mikeyww » 29 Jul 2021, 16:41

The file does not manage standard file attributes. It manages its own, which are editable text and tags. When you use Total Commander to rename, copy, or move the files, it adjusts its description files accordingly. The description files are simply plain text files that Total Commander manages. The user can edit the text via a user interface of the program.

User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: Customisable file field (excluding the file name)?  Topic is solved

Post by submeg » 30 Jul 2021, 04:33

mikeyww wrote:
29 Jul 2021, 08:26
You could use @teadrinker's Explorer_GetSelection, and then use FileMove as you loop through the results.
thanks for the link @mikeyww, I was able to build the solution with it as per below. You are an absolute gem on these forums, another solution you pointed me to, many thanks! :bravo:

How it works:

• User selects the files they wish to rename
• User presses the hotkey
• InputBox appears
• User types in the string they wish to prepend
• The script loops through all the selected files and renames them

The only questions that remains now:
1. How many letters should be allowed in the prefix?
2. What should each character represent?

Any ideas on what the characters should mean? Has this ever been considered / attempted before? My aim is to have just two "buckets" on my OneDrive -

1. Files that are "active" (edited within the last 90 days
2. Everything else

Keen for any suggestions / feedback / possible issues!

I'm going to investigate Total Commander now.

Code: Select all


#SingleInstance, Force

F3::

FileRenamer()

msgbox % "fin."

Return

;-------------------------------------------------------------


;-------------------------------------------------------------
FileRenamer()
{

;Input box method
LongText := "There are x characters:`r`r1. In/Out`t`t`tCreated by the user or other`r2. Something`t`tused for something`r3. Something else`t`tused for something else..."

InputBox, UserInput, - PREFIX BUILDER -, %LongText%, , 500, 300
if ErrorLevel
{
    MsgBox, CANCEL was pressed.
    Return
}
else
{
    FilePrefix := UserInput . "_"
}

;=====================================
;THE GUTS OF THE FUNCTION START HERE
;=====================================
;https://www.autohotkey.com/boards/viewtopic.php?style=17&p=255256#p255256
;what is the class of the currently active program?    
WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")

if !(winClass ~="Progman|WorkerW|(Cabinet|Explore)WClass")
{
    
    msgbox % "not the correct class..."
    Return
    
}

shellWindows := ComObjCreate("Shell.Application").Windows

if (winClass ~= "Progman|WorkerW")
{
    shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP := 8, 0, SWFO_NEEDDISPATCH := 1).Document
}
else 
{
    for window in shellWindows
    {
        if (hWnd = window.HWND) && (shellFolderView := window.Document)
        {
            break
        }
    }
}
    
;cycle through the selected files (i.e. modifies each file individually)
for item in shellFolderView.SelectedItems
{
       
    ;Find the full path
    FullPath := item.Path
    
    ;https://www.autohotkey.com/docs/commands/SplitPath.htm
    SplitPath, FullPath, name, dir, ext, name_no_ext, drive
    
    ;update the sections to include the slashes and dots
    dir := dir . "\" 
    ext := "." ext
    
    ;-------------------------------------------------------------
    NewFullPath := dir . FilePrefix . name_no_ext . ext
    
    FileMove, %FullPath%, %NewFullPath%
    
    if (ErrorLevel)
    msgbox Error; can't rename file.

}

;=====================================
;THE GUTS OF THE FUNCTION END HERE
;=====================================

}
Return
;-------------------------------------------------------------

____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

Post Reply

Return to “Ask for Help (v1)”