Avatar of Shanan212
Shanan212Flag 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
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Shanan212
Shanan212
Flag of Canada image

ASKER

Thanks!
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

No problem.  Did it work for Ok for you then?
Avatar of Shanan212
Shanan212
Flag of Canada image

ASKER

Yes, I used the concept and adjusted here and there.
Thanks!
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

No problem, just checking you had all you needed.

Steve
Windows Batch
Windows Batch

Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.

13K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo