Avatar of Shanan212
Shanan212
Flag for Canada asked on

If statement and getting file name

set aday = %date:~3,2%
set bday = %date:~3,2%
IF %aday% GTR %bday% echo "bigger"

Open in new window


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

Open in new window


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

Open in new window


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!
Windows Batch

Avatar of undefined
Last Comment
Steve Knight

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Steve Knight

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Shanan212

ASKER
Thanks!
Steve Knight

No problem.  Did it work for Ok for you then?
Shanan212

ASKER
Yes, I used the concept and adjusted here and there.
Thanks!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Steve Knight

No problem, just checking you had all you needed.

Steve