1

I have the following code that copies certain files from one folder into another. I want to name the copied file to 'Customer Dets'. I want to do it in the same batch file if possible.

@ECHO OFF
FOR /F "tokens=2 delims= " %%V IN ("%DATE%") DO SET TDY=%%V   
xcopy  /y "C:\Users\rnan\Desktop\Batch Files\KGP\FileHistory\*Customer*" "C:\Users\rnan\Desktop\Batch Files\*.*" /d:%TDY%     
SET TDY=
aschipfl
  • 33,626
  • 12
  • 54
  • 99
qwerty
  • 887
  • 11
  • 33
  • if you rename your files to a static name, won't you overwrite the file at every iteration of your loop? – blaze_125 Apr 19 '17 at 17:36
  • @blaze_125 That is the plan. Its the end of the day file, so everyday i want to replace the existing file with a new file with the same name. – qwerty Apr 19 '17 at 17:42
  • @blaze_125 There is no loop here. The for loop is for storing the date in TDY variable. – qwerty Apr 19 '17 at 17:52
  • My bad. Something like this should work `echo F|xcopy /y "c:\temp\3075.pdf" "C:\temp\newfilename.txt"`. `echo F|` pipes the answer to `is this a directory or file` question that comes up if you try to xcopy a file over to a location which does not already exist. – blaze_125 Apr 19 '17 at 18:01
  • If i found the answer do i delete the question or answer it myself? – qwerty Apr 19 '17 at 18:05
  • @blaze_125 it was a file question, it was fairly easy. I deleted the existing file and then renamed the file that was being copied. This file goes into ssis packages due to which i need just one file in that folder. – qwerty Apr 19 '17 at 18:07
  • Related: [XCOPY still asking (F = file, D = directory) confirmation](http://stackoverflow.com/a/33770152) – aschipfl Apr 19 '17 at 18:41

1 Answers1

1

You can simply use ren "pathofthefile\file_name" "new file name"

Rahul
  • 903
  • 1
  • 10
  • 27