Issues with .BAT File Adding todays date

Hello,
I have the two below .BAT files and I need them to move and date the file. Below is the language I have. The file does move but it is not adding "today's date". Instead just overwriting.

#1
@echo off
For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
  Set Day=%%A
  Set Month=%%B
  Set Year=%%C
  Set All=%%A%%B!Year:~-2!
)
Copy "G:\CLSINC\Provana Queries\Daily Letters\DantomPrevDay_.xlsx" "G:\CLSINC\Provana Queries\Daily Letters\Older\DantomPrevDay_!All!.xlsx"
"E:\CLS Queries\Provana Database.accdb" /x LettersDailyAudit


#2
@echo off
For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
  Set Day=%%A
  Set Month=%%B
  Set Year=%%C
  Set All=%%A%%B!Year:~-2!
)
Copy "G:\CLSINC\Provana Queries\Daily Scans\ScansPrevDay_.xlsx" "G:\CLSINC\Provana Queries\Daily Scans\Older\ScansPrevDay_!All!.xlsx"
"E:\CLS Queries\Provana Database.accdb" /x SansDailyAudit


Thank you
WO2015Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David SankovskySenior SysAdminCommented:
Try Renaming the file before copying...
@echo off
For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
  Set Day=%%A
  Set Month=%%B
  Set Year=%%C
  Set All=%%A%%B!Year:~-2!
)
rename "G:\CLSINC\Provana Queries\Daily Letters\DantomPrevDay_.xlsx" "DantomPrevDay_$All$.xlsx"
Copy "G:\CLSINC\Provana Queries\Daily Letters\DantomPrevDay_$All$.xlsx" "G:\CLSINC\Provana Queries\Daily Letters\Older\DantomPrevDay_$All$.xlsx"

Open in new window

WO2015Author Commented:
So that renamed and moved it but it is still not showing the date, it shows: DantomPrevDay_$All$.xlsx.  The $All$ should be todays day.
Dirk MareSystems Engineer (Acting IT Manager)Commented:
Why not just use %date%
@ ECHO OFF
for /F "tokens=1,2,3 delims=/ " %%i in ("%date%") DO set all=%%i%%j%%k
Copy "G:\CLSINC\Provana Queries\Daily Letters\DantomPrevDay_.xlsx" "G:\CLSINC\Provana Queries\Daily Letters\Older\DantomPrevDay_%All%.xlsx"
"E:\CLS Queries\Provana Database.accdb" /x LettersDailyAudit

Open in new window


DirkMare
David SankovskySenior SysAdminCommented:
MY apologies, I confused he charecter needed:

@echo off
For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
  Set Day=%%A
  Set Month=%%B
  Set Year=%%C
  Set All=%%A%%B!Year:~-2!
)
rename "G:\CLSINC\Provana Queries\Daily Letters\DantomPrevDay_.xlsx" "DantomPrevDay_%All%.xlsx"
Copy "G:\CLSINC\Provana Queries\Daily Letters\DantomPrevDay_%All%.xlsx" "G:\CLSINC\Provana Queries\Daily Letters\Older\DantomPrevDay_%All%.xlsx"

Open in new window


That should work

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WO2015Author Commented:
Hello,

Ok, I went back and tried to look at other scripts because above is not working. I am trying to rename a file with todays date so when the next one runs it will save the older one in a folder and then create the new file and rename it.  Below is what I have.  It is moving the files, and running the script, but the renaming I cant get to work, but its close:

move "G:\CLSINC\Provana Queries\Daily Letters\DantomPrevDay_*.*".xlsx" "G:\CLSINC\Provana Queries\Daily Letters\Older\
"C:\Program Files (x86)\Microsoft Office\Office12\MSACCESS.exe" "E:\CLS Queries\Provana Database.accdb" /x LettersDailyAudit

SETLOCAL ENABLEDELAYEDEXPANSION
@echo off

For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
  Set Day=%%A
  Set Month=%%B
  Set Year=%%C
  Set All=%%A%%B!Year:~-2!
)

Copy "G:\CLSINC\Provana Queries\Daily Letters\DantomPrevDay_.xlsx" "DantomPrevDay_!All!.xlsx"
Del "N:\Scheduled Reports\Affidavit Spreadsheets\DantomPrevDay_.xlsx"
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.