troubleshooting Question

If statement and getting file name

Avatar of Shanan212
Shanan212Flag for Canada asked on
Windows Batch
5 Comments1 Solution297 ViewsLast Modified:
set aday = %date:~3,2%
set bday = %date:~3,2%
IF %aday% GTR %bday% echo "bigger"

Hi,

I am somewhat good at batch-scripting but not to this advanced level :/

What I want to do is, check if file exists in a folder, get portion of the file name and extract a number (date) and check if the date is bigger than 20 then rename the file, if not copy it.

This being renaming the file. I have the code to rename it.

code to rename - working
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "C:\Users\%USERNAME%\Desktop\Database.accdb" "Database BACKUP "%%d-%%e-%%f.accdb

code to copy - working
copy "c:\Users\aravinds\Desktop\Database.accdb" "\\Fileserver\Everyone\ Database\Database\Database\BackUp"

Could anyone please help me with the following

- Check if file exisits with current month and year embded in its name

database - 05/23/2012.accdb

if then (above case yes since it has May & 2012), then check if the database name has date bigger than 20? (in this case, 23, so yes)

If then rename - I have code

if not copy - I have code

Thanks in advance!
ASKER CERTIFIED SOLUTION
Steve Knight
IT Consultancy

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros