rename - I am trying to append today's date to pdfs in a subfolder using a .bat file. Right now I have: -
new -- trying make .bat
file rename files in subfolder, (i want behave %folder%
rather using actual location), adding prefix, abs_ 123
, today's date, _20170818
right have (pseudo):
@echo off %subfolder% (*) ren "%%a" "pre %%a" (*) ren "%%~a" "%%~na ("_%%date)%%~xa"
i agree compos , mofis comments, imo there lot of outdated variants proposed here on with:
- locale/user settings dependent
%date%
,%time%
variables or - the clumsy parse
wmic
variant it's cr/cr/lf sequences. - j-/vbscript solutions require either temp file or hybrid version difficult understand newbies.
using/parsing powershell comes @ small delay, used once in script shouldn't matter.
you may insert day offset different dates.
@echo off /f %%y in ( 'powershell -nop -c "(get-date).adddays(-1).tostring(\"yyyy-mm-dd\")"' ) set yesterday=%%y echo yesterday = %yesterday% /f %%d in ( 'powershell -nop -c "(get-date).adddays(0).tostring(\"mm\/dd\/yyyy\")"' ) set "dt=%%d" echo today mdy = %dt% /f %%t in ( 'powershell -nop -c "(get-date).adddays(+1).tostring(\"yyyy\/mm\/dd\")"' ) set tomorrow=%%t echo tomorrow = %tomorrow% /f %%o in ( 'powershell -nop -c "(get-date).adddays(0).tostring(\"o\")"' ) set iso8601=%%o echo iso8601 = %iso8601% /f "delims=" %%u in ( 'powershell -nop -c "(get-date).adddays(0).tostring(\"u\")"' ) set utc=%%u echo utc = %utc% /f "delims=" %%f in ( 'powershell -nop -c "(get-date).adddays(0).tostring(\"f\")"' ) set fulldt=%%f echo fulldt = %fulldt%
output on german locale system, day-/month names come in locale.
yesterday = 2017-08-17 today mdy = 08/18/2017 tomorrow = 2017/08/19 iso8601 = 2017-08-18t17:06:46.1050969+02:00 utc = freitag, 18. august 2017 15:06:46 fulldt = freitag, 18. august 2017 17:06:46
see this link more format specifiers
Comments
Post a Comment