Adding name to file name when saved in Sub-Folder
-
CookieMonster
Adding name to file name when saved in Sub-Folder
I need a script that can automatically add [stamp]_<filename> to a file name when it is placed in a specific sub-folder, there are two other names I want to add before the file name not just [stamp] in-case I forget to add the name to the file name when saving in a program hoping XY can do this automatically ?
-
CookieMonster
Re: Adding name to file name when saved in Sub-Folder
Maybe my last post didn't make much sense.
When a file is placed in a specific sub-folder I want an extension to be added to the beginning of the file name for example [brush]_flacky.ext, when it is saved in the sub-folder it won't have the extension, in this case the extension is within the brackets including the brackets followed by an underscore then the file name that I had originally gave the file.
When a file is placed in a specific sub-folder I want an extension to be added to the beginning of the file name for example [brush]_flacky.ext, when it is saved in the sub-folder it won't have the extension, in this case the extension is within the brackets including the brackets followed by an underscore then the file name that I had originally gave the file.
-
highend
- Posts: 14942
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Adding name to file name when saved in Sub-Folder
No such automation is possible within XY.
You need a monitor software, that executes applications on creation of files.
E.g.: http://www.nodesoft.com/foldermonitor
Additionally AutoHotkey or different scripting language (even a batch file would be sufficient).
An Example:
Extract foldermonitor into a new directory.
Start it.
Right click on the tray icon, choose "Options..."
Tab "Events":
Only check "Created".
Tab "Visual notification"
Check "No visual notification"
Uncheck "Stop screen saver"
Tab "Sound notification"
Check "No sound"
Tab "Execute command"
Command: D:\notify.exe
Arguments: "{0}{1}"
Then add all the folders that you want to monitor.
Step two:
Get AutoHotkey_L and it's compiler
Save this as D:\notify.ahk
Use the compiler to compile it to D:\notify.exe
Whenever foldermonitor is running and a new file is created in D:\Temp\Brushes
E.g.: "nice brush.png"
it will be automatically renamed to D:\Temp\Brushes\[brush]_nice brush.png
Ofc you have to change that directory name in the ahk script and the [<content>] as well...
and don't forget to recompile your script afterwards^^
You need a monitor software, that executes applications on creation of files.
E.g.: http://www.nodesoft.com/foldermonitor
Additionally AutoHotkey or different scripting language (even a batch file would be sufficient).
An Example:
Extract foldermonitor into a new directory.
Start it.
Right click on the tray icon, choose "Options..."
Tab "Events":
Only check "Created".
Tab "Visual notification"
Check "No visual notification"
Uncheck "Stop screen saver"
Tab "Sound notification"
Check "No sound"
Tab "Execute command"
Command: D:\notify.exe
Arguments: "{0}{1}"
Then add all the folders that you want to monitor.
Step two:
Get AutoHotkey_L and it's compiler
Code: Select all
#SingleInstance force
#NoTrayIcon
Sleep, 2000 ; Give an application time to save it's file
StringReplace, iVar, 1, ",, All
; Only proceed if it's really a file (not on directories)
FileGetAttrib, Attributes, %iVar%
IfNotInString, Attributes, D
{
path_only := RegExReplace(iVar, "\\[^\\]*$", "")
file_only := RegExReplace(iVar, ".*\\", "")
base_only := RegExReplace(file_only, "\.[^\.]*$", "")
IfInString, iVar, D:\Temp\Brushes
{
newName := "[brush]_" . file_only
FileMove, %iVar%, %path_only%\%newName%
}
}
Use the compiler to compile it to D:\notify.exe
Whenever foldermonitor is running and a new file is created in D:\Temp\Brushes
E.g.: "nice brush.png"
it will be automatically renamed to D:\Temp\Brushes\[brush]_nice brush.png
Ofc you have to change that directory name in the ahk script and the [<content>] as well...
and don't forget to recompile your script afterwards^^
One of my scripts helped you out? Please donate via Paypal
-
CookieMonster
Re: Adding name to file name when saved in Sub-Folder
Thank you, with some help I have a functioning AHK script, works nice 
XYplorer Beta Club