Solved

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

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.
9 answers Last reply Best Answer
More about create file append date files
  1. something like this should work:
    
    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:
    
    for %%i in (*.txt) do (ren "%%i" "%date% %%i")
    
  2. Sunius said:
    something like this should work:
    
    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:
    
    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'
  3. Best answer
    you forgot quotation marks! like this
    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.
  4. Sunius said:
    you forgot quotation marks! like this
    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"
  5. figured it out...needed to use some old DOS commands to get it to read the bat file correctly...
  6. Mind posting a solution here so others could see it? :).
  7. /A:R needed to be used to removed the read only from the files

    Sunius, thanks for the help
  8. Best answer selected by BossHogg20.
  9. Ah I see. Glad I helped you even if it was little help :).
Ask a new question

Read More

Programming Apps