File Rename based on date.

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
smpayne
Newbie
Posts: 9
Joined: Mon Nov 01, 2004 8:21 pm
Location: Michigan
Contact:

File Rename based on date.

Post by smpayne » Mon Nov 01, 2004 8:27 pm

I have several files located and named as follows:

S:\CTV\102904pool55inv.txt

This file is auto created every day and the modified date reflecting each day. I need to automatically look in this directory for these files that are new every morning and rename then and copy them to this location:

\\MINT02\Share\SHARE\SMP\Dialer_Recon\pool55inv.txt

This then allows me to complete an automation within an Access database.

Any ideas??

Much appreciated!

Shawn.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Nov 01, 2004 9:32 pm

Two quick skeleton structures:
----------------------------

Use System date, and parse it to get components for filename.

Month>MM
Day>DD
Year>YYYY
MidStr>%Year%,3,2,YY

Use %MM%%DD%%YY% when looking for the file name

Let>FileName=%MM%%DD%%YY%pool55inv.txt
------------------------
or
Use FileDate> and compare results to known value. If changed then do MoveFile>

You could use todays date as a reference.
or
Compare FileDate to a value in an INI file. Update the INI value every time you move the existing file.
-------------------
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

smpayne
Newbie
Posts: 9
Joined: Mon Nov 01, 2004 8:21 pm
Location: Michigan
Contact:

Format

Post by smpayne » Mon Nov 01, 2004 9:52 pm

Thanks so much for your reply Bob. I am so new to this. So, how would this scrupt look laid out. Am I replacing my filename is the variable "FileName". And when I write the line to copy, what does the syntax look like.

I really appreciate your assistance!

Shawn.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Nov 01, 2004 10:15 pm

And when I write the line to copy, what does the syntax look like.
Put together your script and submit here if you have problems. Explain where the problem is happening and what you are seeing for symptoms of problems.

Maybe use this structure as a starting point. This is untested
Let>SourcePath=S:\CTV
Let>DestPath=\\MINT02\Share\SHARE\SMP\Dialer_Recon

Month>MM
Day>DD
Year>YYYY
MidStr>%Year%,3,2,YY
Let>FileName=%MM%%DD%%YY%pool55inv.txt

IfFileExists>%SourcePath%\%FileName%,CopyIt
MessageModal>File %Filename% was NOT found in %SourcePath%%CRLF%CRLF%No file copied. Process Stopped.
Goto>End

Label>CopyIt
MoveFile>%SourcePath%\%FileName%,%DestPath%\%FileName%,
MessageModal>File %Filename% was found in %SourcePath%.%CRLF%%CRLF%. File was copied to %DestPath%.

Label>End
Try starting with the Help file for each of the commands and variables, and look at the Help examples. You can also single step through the script and look at the values in the Watch List. And you can read your log and see what happened, what variable values were, and time and sequence commands were executed/skipped.

If copying script from forum be sure to remove any trailing spaces. Latest version does warn you of trainling spaces. And Variables and Labels are Case Sensitive.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

smpayne
Newbie
Posts: 9
Joined: Mon Nov 01, 2004 8:21 pm
Location: Michigan
Contact:

Close!

Post by smpayne » Tue Nov 02, 2004 2:18 pm

Thanks for your assistance Bob, so very much appreciated! Everythings seems to run smooth, with the exception of the following MidStr command. After stepping through, it looks for the filename:

1102eapool55inv.txt

MidStr>%Year%,3,2,YY
Let>FileName=%MM%%DD%%YY%pool55inv.txt

I attempted changing some of the values but the closest I got was in getting the full YYYY format in the file name.

Thanks again!!!

smpayne
Newbie
Posts: 9
Joined: Mon Nov 01, 2004 8:21 pm
Location: Michigan
Contact:

Good advice

Post by smpayne » Tue Nov 02, 2004 2:22 pm

Bob, I took your advice and studied the Syntax and found that by replacing this:

MidStr>%Year%,3,2,YY

With this:

MidStr>%YYYY%,3,2,YY

It corrected the issue.

Thanks so much for your guidance!

Shawn.

smpayne
Newbie
Posts: 9
Joined: Mon Nov 01, 2004 8:21 pm
Location: Michigan
Contact:

mmm

Post by smpayne » Tue Nov 02, 2004 2:32 pm

Everything looks fine and it says the file has been copied correctly, but when I look in the destination folder, it does not exist??

Any ideas?

Shawn

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Nov 02, 2004 2:54 pm

Hello smpayne. Good catch on the %YYYY% vs. the %Year%. I warned you it was untested :roll:

:idea: It is possible that the file did not get copied. That was a basic structure that I provided. This script message happens regardless of whether the file was copied or not.

Normally after a MoveFile, CopyFile, etc. you would frequently have some other commands to check that it happened, something like IfFileExists> SendMessageOK,SendMessageNG; or maybe FileDate> result would be analyzed, etc.

Make a log and look at the log results, or Single Step while looking at the Watch List to see the values of the variables.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

smpayne
Newbie
Posts: 9
Joined: Mon Nov 01, 2004 8:21 pm
Location: Michigan
Contact:

Step looks good

Post by smpayne » Tue Nov 02, 2004 3:22 pm

Bob, the step looks good and appears to execute. I put an IfFileExists check on the destination and it comes up successful. I even tried changing to a locat directory, but still no file. Here is what I have right now:

Let>SourcePath=S:\CTV
Let>DestPath=\\MINT02\Share\SHARE\SMP\DialerRecon

Month>MM
Day>DD
Year>YYYY
MidStr>%YYYY%,3,2,YY
Let>FileName=%MM%%DD%%YY%pool55inv.txt
Let>NewFileName=pool55inv.txt

IfFileExists>%SourcePath%\%FileName%,CopyIt
MessageModal>Unable to locate %Filename% in %SourcePath%%CRLF%CRLF%No file copied. Process Stopped.
Goto>End

Label>CopyIt
CopyFile>%SourcePath%\%FileName%,%DestPath%\%NewFileName%,
MessageModal>File %Filename% was found in %SourcePath%.%CRLF%%CRLF%. File was copied to %DestPath%.

IfFileExists>%DestPath\%NewFileName%,Success
Label>Success
MessageModal>File Found
Goto>End

Label>End

Any ideas??

Thanks again Bob!!

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Nov 02, 2004 3:58 pm

I see a trailing comma on the line to CopyFile.
CopyFile>%SourcePath%\%FileName%,%DestPath%\%NewFileName%,
Remove that comma

And your check for Success will give you a Success message in all cases.
IfFileExists>%DestPath\%NewFileName%,Success
Label>Success
MessageModal>File Found
Goto>End
You need something like:
IfFileExists>%DestPath\%NewFileName%,Success,Fail

Label>Success
MessageModal>File Found
Goto>End

Label>Fail
MessageModal>File Not Found
Goto>End
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

smpayne
Newbie
Posts: 9
Joined: Mon Nov 01, 2004 8:21 pm
Location: Michigan
Contact:

Thank you!

Post by smpayne » Tue Nov 02, 2004 4:47 pm

Works great!!! Thanks for the quick and helpfull lesson!


One last question.. How do I change the CL_OVERWRITE=0 variable to 1?? I have looked through the program and the .ini file, but cannot locate it.

Shawn

smpayne
Newbie
Posts: 9
Joined: Mon Nov 01, 2004 8:21 pm
Location: Michigan
Contact:

Sorry Bob, nevermind...me being stupid now!

Post by smpayne » Tue Nov 02, 2004 5:01 pm

Just used a Let statement.

Thanks for everything!!!! You saved me a lot of grief.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Nov 02, 2004 8:47 pm

Glad you found the Let> statement.

For the record, that was the CF_OVERWRITE you wanted, vs. CL_OVERWRITE, correct?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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