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

Status
Not open for further replies.

BossHogg20

Honorable
Jul 20, 2012
6
0
10,510
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.
 
Solution
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
390
0
19,060
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

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
390
0
19,060
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.
 
Solution

BossHogg20

Honorable
Jul 20, 2012
6
0
10,510


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"
 
Status
Not open for further replies.