Copy file from a folder to a folder with filename and rename to timestamp

123 Views Asked by At

I never do batch programming and i would like to create a batch file to get all *.cfg file from a folder and copy the file to another folder named with the filename and rename the file with is creation time stamp.

For exemple move c:\a.cfg to c:\test\a\20131213.cfg

Thx

1

There are 1 best solutions below

0
On

I've writed that code but i still have 2 problems:

1) if the cfg file name is in 2 word, it create 2 folders (one with the first word, one with the second word) and didn't copy the file. If the name is in 1 word, it create the folder and copy the file in it.

2) how can i rename the filename to it's creation timestamp.

@ECHO OFF
setlocal enabledelayedexpansion
FOR %%f in (*.cfg) DO (
  set filename=%%f
  set filename2="test"
  set folder=!filename:~0,-4!
  set copypath=C:\Users\k.trasschaert\Desktop\test\!folder!
  mkdir !folder!
  copy !filename! !copypath!\!filename!

)

pause