Jump to content

Adding date to the name of files and folders

Go to solution Solved by Jacques Cartier,
1 hour ago, Joshua said:

Hi Jacques, we had a similar conversation a few days ago regarding searching a filename.

KCDaRookie on Reddit found the solution:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force

SelFile = %1%

FileGetTime, FileTimeStamp, %SelFile%
FormatTime FileTimeStamp,%FileTimeStamp%, yyyy-MM-dd

FileGetAttrib, IsFolder, %SelFile%

If InStr(IsFolder, "D" )
{
NewName := RegExReplace(SelFile, "$"," - " . FileTimeStamp)

FileMoveDir, %SelFile%, %NewName%
}
Else
{
NewName := RegExReplace(SelFile, "(\.[^\.]+)$"," - " . FileTimeStamp . "$1")

FileMove, %SelFile%, %NewName%
}

 

Hi, I would like to add the "Date Created" or "Date Modified" to any files or folders. Possibly by right-clicking on it and running a script from the context menu. Can that be done with autohotkey, batch file or VBS ? Any help would be appreciated

example: "test.txt" to "test 2020-10-19.txt"
 

Link to comment
Share on other sites

Link to post
Share on other sites

I use Total Commander's Multi-Rename Tool  ... you can download TC from the official website : https://www.ghisler.com/download.htm

 

 

Select the files or folders with Insert key , or with + or * key or dragging with right mouse button , then File > MultiRename Tool ... and you can add as many modifiers in the file name or extension or whatever.

 

See https://www.howtogeek.com/56580/how-to-rename-many-files-at-once-with-total-commander/

 

image

 

The plugin button opens up a huge list of options including last modified, last access etc etc

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks for the help. I already use free commander. I need to open commander, navigate to the file, click on file, multirename, select profiles and rename. I want to speed up the process.  Right-click, click on the script.

Link to comment
Share on other sites

Link to post
Share on other sites

Hi Jacques, we had a similar conversation a few days ago regarding searching a filename. I am going to ignore your preference of using total commander here. As we mentioned before, you can add whatever you like to your context menu via the following reg edit:

[HKEY_CLASSES_ROOT\Directory\shell\Run Batch script]
@="&Run Batch script"

[HKEY_CLASSES_ROOT\Directory\shell\Run Batch script\command]
@="\"H:\\BATCH_FILE_PATH\\context-batch.bat\" \"%1\""

You can use the existing %date% and %time% environment variables to get date/time in batch. You can concatenate them or format them however you want with the name of the file etc. 

 

My suggestion would be to map a script written in a 'proper' language to this, such as python. I can give you hand with the script if you'd like. Lastly, if the filename modification is identical for each file, you could just write a macro that utilises the "F2" shortcut to rename, home/end keys to navigate the cursor and then obviously output todays date as the suffix/prefix to the filename.

Ryzen 5 1500x, Noctua NH-L9x65 SE-AM4, GA-AB350N, 16GB 1600Mhz, EVGA GTX 970, 250GB Samsung 960 Evo, 120GB Samsung 840 Evo, 1TB WD Green & 2TB Seagate Barracuda. 650w OCZ ZX & Cooler Master Elite 130. Acer CB241HQK 4K, LG IPS234V-PN 1080p, Ducky Zero Shine All Blue/Anne Pro Brown/SteelSeries Apex Pro & Razer Naga 2014

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Joshua said:

Hi Jacques, we had a similar conversation a few days ago regarding searching a filename.

KCDaRookie on Reddit found the solution:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force

SelFile = %1%

FileGetTime, FileTimeStamp, %SelFile%
FormatTime FileTimeStamp,%FileTimeStamp%, yyyy-MM-dd

FileGetAttrib, IsFolder, %SelFile%

If InStr(IsFolder, "D" )
{
NewName := RegExReplace(SelFile, "$"," - " . FileTimeStamp)

FileMoveDir, %SelFile%, %NewName%
}
Else
{
NewName := RegExReplace(SelFile, "(\.[^\.]+)$"," - " . FileTimeStamp . "$1")

FileMove, %SelFile%, %NewName%
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×