IfFileExist

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
pr4t3ek
Newbie
Posts: 4
Joined: Thu Dec 18, 2008 11:42 am

IfFileExist

Post by pr4t3ek » Thu Dec 18, 2008 11:48 am

I have the following code:

Code: Select all

IfFileExists>C:\Documents and Settings\Pratik\Desktop\Report\Dec 2008\TestFile 18-12-2008.xls
//do something
The problem is that everyday there is a new file created with todays date and i need the iffileexists function to work on the file which has todays date after testfile ....

How can i amend the above code so that it firstly is checking todays date

and also amend the macro in a way so that it picks up "Dec 2008" as the current month and year (because this is the naming convention used where the file is located)..

i hope i can get some help around this. Thank You

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Dec 18, 2008 12:24 pm

Like so:

Code: Select all

Year>yyyy
Month>mm
Day>dd
IfFileExists>C:\Documents and Settings\Pratik\Desktop\Report\Dec 2008\TestFile %dd%-%mm%-%yyyy%.xls
  //do something
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

pr4t3ek
Newbie
Posts: 4
Joined: Thu Dec 18, 2008 11:42 am

Post by pr4t3ek » Thu Dec 18, 2008 12:29 pm

So im assuming, for the Dec 2008 issue, I can just go:

Code: Select all

Year>yyyy
Month>mm
Day>dd
Month>mmm
IfFileExists>C:\Documents and Settings\Pratik\Desktop\Report\%mmm% %yyyy%\TestFile %dd%-%mm%-%yyyy%.xls
  //do something
Endif
??

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Dec 18, 2008 12:34 pm

Sorry, missed that part. No, you can't do that - Month returns the 2 digit month number. Makes no difference what variable you use to return it it will always be the 2 digit month number.

You can use VBScript's MonthName function. Like so:

Code: Select all

VBSTART
VBEND

Year>yyyy
Month>mm
Day>dd
VBEval>MonthName(%mm%,true),month_name

Let>path=C:\Documents and Settings\Pratik\Desktop\Report\%month_name% %yyyy%\TestFile %dd%-%mm%-%yyyy%.xls

IfFileExists>path
  //do something
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Dec 18, 2008 12:40 pm

Or, let's say you have non-standard month abbreviations, you could make your own lookup:

Code: Select all

VBSTART
  'custom month names
  month_array = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
VBEND

Year>yyyy
Month>mm
Day>dd

//get month name from month number
VBEval>month_array(%mm%-1),month_name

Let>path=C:\Documents and Settings\Pratik\Desktop\Report\%month_name% %yyyy%\TestFile %dd%-%mm%-%yyyy%.xls

IfFileExists>path
  //do something
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts