1

I have a file that is generated with the current date using the Month, Day and Year. Previously this file did not include a date and I used a script with the _%All% in a batch file to move the file to a different folder and this works fine.

I now need the correct syntax to use so that the script will take the file with the current date and continue to have the script move the file into a backup folder.

The following is the script that has been used successfully.

@echo off
@For /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do @(
  Set DayW=%%A
  Set Day=%%B
  Set Month=%%C
  Set Year=%%D
  Set All=%%A%%B%%C%%D
  )

move \\crserverXX\Batch\ASCII\OCR1_CRM\OCR1.CSV \\crserverXX\Batch\ASCII\OCR_Backup\OCR1.CSV
ren \\crserverXX\Batch\ASCII\OCR_Backup\OCR1.CSV OCR1_%All%.CSV
move \\crserverXX\Batch\ASCII\OCR1_CRM\OCR1.CSV.bak \\crserverXX\Batch\ASCII\OCR_Backup\OCR1.CSV.bak
ren \\crserverXX\Batch\ASCII\OCR_Backup\OCR1.CSV.bak OCR1_%All%.CSV.bak

The issue now is that the file generated each day will also include the date as in the following: OCR1081916.CSV.

What is the correct way to use the date variable so that it will move the OCR1 file regardless of the date?

  • 1
    We are neither mind readers or psychic. Please edit your question and include all the relevant information. That includes some example file names you want to move and, of course, the missing batch file that doesn't work. – DavidPostill Aug 18 '16 at 16:04
  • You were asked to edit the question. This is so your code can be properly formatted and readable (which is not the case if the code is in a comment). – DavidPostill Aug 21 '16 at 14:13
  • What is the output of date /t in your locale? – DavidPostill Aug 21 '16 at 14:20
  • The output is Eastern Time. This is an example from August 15. OCR1_Mon08152016.CSV – RogerV Aug 21 '16 at 14:31
  • So instead of OCR1_Mon08152016.CSV you want the name to be OCR1081516.CSV? In other words %All% should be 081516? Please be clear and give examples of the source and target filenames (which is what I asked for in my very first comment). – DavidPostill Aug 21 '16 at 14:42
0

I need the script to move the file from the original location to the backup location

At this point since the file is generated with a date each day

You can scrap most of your batch file in this case. All the code to manipulate the date and to rename files is not needed.

Use the following batch file:

@echo off
move \\crserverXX\Batch\ASCII\OCR1_CRM\OCR1*.CSV \\crserverXX\Batch\ASCII\OCR_Backup\
move \\crserverXX\Batch\ASCII\OCR1_CRM\OCR1*.CSV.bak \\crserverXX\Batch\ASCII\OCR_Backup\

Further Reading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.