Sign in with
Sign up | Sign in
Your question
Solved

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

Last response: in Applications
Share
July 20, 2012 7:15:56 PM

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.
a b L Programming
July 21, 2012 6:43:19 AM

something like this should work:
  1. ren "first.txt" "%date% first.txt"
  2. ren "middle.txt" "%date% middle.txt"
  3. ren "last.txt" "%date% last.txt"


To append date to all .txt files in the folder:
  1. for %%i in (*.txt) do (ren "%%i" "%date% %%i")
m
0
l
July 23, 2012 3:35:37 PM

Sunius said:
something like this should work:
  1. ren "first.txt" "%date% first.txt"
  2. ren "middle.txt" "%date% middle.txt"
  3. ren "last.txt" "%date% last.txt"


To append date to all .txt files in the folder:
  1. for %%i in (*.txt) do (ren "%%i" "%date% %%i")


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'
m
0
l
Related resources

Best solution

a b L Programming
July 23, 2012 4:50:00 PM

you forgot quotation marks! like this
  1. 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.
Share
July 23, 2012 5:49:58 PM

Sunius said:
you forgot quotation marks! like this
  1. 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.


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"
m
0
l
July 24, 2012 5:51:52 PM

figured it out...needed to use some old DOS commands to get it to read the bat file correctly...
m
0
l
a b L Programming
July 24, 2012 8:02:31 PM

Mind posting a solution here so others could see it? :) .
m
0
l
July 25, 2012 1:06:04 PM

/A:R needed to be used to removed the read only from the files

Sunius, thanks for the help
m
0
l
July 25, 2012 2:29:43 PM

Best answer selected by BossHogg20.
m
0
l
a b L Programming
July 25, 2012 2:40:07 PM

Ah I see. Glad I helped you even if it was little help :) .
m
0
l
!