Windows timestamp text filename
April 1, 2020 1:21 AM Subscribe
I'm looking for a way to do date and time stamps in windows (especially for renaming filenames, but anywhere else too).
I was going to try autohotkey but the site gives a warning, IDK how real that warning is but more wary than usual due to general weirdness.
The format I need is
Year Month Date Hours Minutes, like this:
20200401 2111
Does anyone know how to do this?
The format I need is
Year Month Date Hours Minutes, like this:
20200401 2111
Does anyone know how to do this?
Best answer: You can do this with a couple of lines of PowerShell:
I'm not entirely clear where you which date you want. Do you want the creation date from the file itself and incorporate it as part of the name?
Here is how to prepend a folder full of files with the file creation date
$files = get-childitem "c:\yourfolder"
foreach($file in $files){
$name = get-date($file.CreationTime) -Format "yyyyMMdd_hhMM"
Rename-Item -path $file.fullname -NewName "$($file.DirectoryName)\$($file.CreationTime.tostring("yyyyMMdd_hhMM"))_$($file.Name)"
}
posted by jmsta at 6:50 AM on April 1, 2020
I'm not entirely clear where you which date you want. Do you want the creation date from the file itself and incorporate it as part of the name?
Here is how to prepend a folder full of files with the file creation date
$files = get-childitem "c:\yourfolder"
foreach($file in $files){
$name = get-date($file.CreationTime) -Format "yyyyMMdd_hhMM"
Rename-Item -path $file.fullname -NewName "$($file.DirectoryName)\$($file.CreationTime.tostring("yyyyMMdd_hhMM"))_$($file.Name)"
}
posted by jmsta at 6:50 AM on April 1, 2020
If you prefer Linux stuff, you could install the Windows Subsystem for Linux and your preferred distribution and then use whatever command-line Linux tools you like. This would be overkill for this one task, but it's an option.
posted by bright flowers at 7:49 AM on April 1, 2020
posted by bright flowers at 7:49 AM on April 1, 2020
Response by poster: Thank you Lanark, that works really well for me at moment. I edited line 29 to:
Set _datetime=%_DTS:~0,4%%_DTS:~4,2%%_DTS:~6,2% %_DTS:~8,2%%_DTS:~10,2%
to get filename format - filename 20200404 1740.extension
Chrome won't let me download Autohotkey and I'm super cautious at the moment. Maybe in the PC era.
jimsta yes that is the correct date format, I haven't tried your one yet but with Lanark's script and your prepend script I have both ends of the problem solved! Thank you all very much.
posted by unearthed at 12:39 AM on April 4, 2020
Set _datetime=%_DTS:~0,4%%_DTS:~4,2%%_DTS:~6,2% %_DTS:~8,2%%_DTS:~10,2%
to get filename format - filename 20200404 1740.extension
Chrome won't let me download Autohotkey and I'm super cautious at the moment. Maybe in the PC era.
jimsta yes that is the correct date format, I haven't tried your one yet but with Lanark's script and your prepend script I have both ends of the problem solved! Thank you all very much.
posted by unearthed at 12:39 AM on April 4, 2020
This thread is closed to new comments.
For renaming files with the date, you can use a script like this one (self link)
If you save this as a batch script (stampme.cmd) on the desktop, you can drag and drop any file, from a local drive or UNC path, and drop it onto the icon - that will rename the file without moving it from the original location.
By default that does ISO 8601 date format, but you can easily modify it to a different format by adjusting the script.
posted by Lanark at 2:41 AM on April 1, 2020 [4 favorites]