Create a .bat file to append a date to several files

BossHogg20

Honorable
Jul 20, 2012
6
0
10,510
0
HI

Need to create a .bat file to place in a .exe file to append the date to the beginning of the files.

i.e. first.txt; middle.txt; last.txt would need to have the date added to the beginning.

Was able to see several example on google, but none seemed to do what I needed.

The format doesn't matter. Information I left out was that there are only 22 of 100 files that I need to rename that are all in the same folder. I know I need to specifically state the names of the files in the .bat file, but wasn't sure how.
 

Sunius

Distinguished
Dec 19, 2010
391
0
19,060
35
you forgot quotation marks! like this
Code:
ren "C:\Program Files\Hurco\winpc32\ladders\data\TCHGR006.L88" %date%TCHGR006.L88"
I'd also not use absolute path. Just place the .bat file in the same folder as the file.
 

Sunius

Distinguished
Dec 19, 2010
391
0
19,060
35
something like this should work:
Code:
ren "first.txt" "%date% first.txt"
ren "middle.txt" "%date% middle.txt"
ren "last.txt" "%date% last.txt"
To append date to all .txt files in the folder:
Code:
for %%i in (*.txt) do (ren "%%i" "%date% %%i")
 

BossHogg20

Honorable
Jul 20, 2012
6
0
10,510
0
Can't get that to work. Renaming isn't working at all actually. Also tried

Set FileDate=%date:/=%
ren C:\Program Files\Hurco\winpc32\ladders\data\TCHGR006.L88 %date%TCHGR006.L88

even tried using 'rename' instead of 'ren'
 

Sunius

Distinguished
Dec 19, 2010
391
0
19,060
35
you forgot quotation marks! like this
Code:
ren "C:\Program Files\Hurco\winpc32\ladders\data\TCHGR006.L88" %date%TCHGR006.L88"
I'd also not use absolute path. Just place the .bat file in the same folder as the file.
 

BossHogg20

Honorable
Jul 20, 2012
6
0
10,510
0


It will work in folders outside of Program files, so I tried to add some attributes, but it won't rename the files

takeown /F C:\Program Files\Hurco\winpc32\ladders\data\* /R /D Y
icacls C:\Program Files\Hurco\winpc32\ladders\data\* /grant administrators:R /t

ren "C:\Program Files\Hurco\winpc32\ladders\data\TCHGR006.L88" "%date%TCHGR006.L88"
ren "C:\Program Files\Hurco\winpc32\ladders\data\TCHGR006.L88.PAR" "%date%TCHGR006.L88.PAR"
 
Thread starter Similar threads Forum Replies Date
PepeTheDog Apps General Discussion 3
S Apps General Discussion 6
A Apps General Discussion 5
T Apps General Discussion 1
S Apps General Discussion 4
T Apps General Discussion 1
M Apps General Discussion 1
M Apps General Discussion 1
R Apps General Discussion 1
M Apps General Discussion 2
G Apps General Discussion 1
M Apps General Discussion 2
C Apps General Discussion 4
A Apps General Discussion 1
D Apps General Discussion 4
J Apps General Discussion 11
thegamersite1 Apps General Discussion 1
G Apps General Discussion 1
M Apps General Discussion 4
Can You Help Me Please Apps General Discussion 3

ASK THE COMMUNITY