Technical support and scripting issues
Moderators: JRL, Dorian (MJT support)
-
BlackWisdom
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
Post
by BlackWisdom » Thu Dec 16, 2004 8:37 am
Hi guys I been up a while trying to piece this one together - Im trying to copy all the files from yesterday for a specific extension to a folder (any folder) here is what I have so far
FileDate>c:\*.doc,builddate
MidStr>builddate,1,4,y
MidStr>builddate,5,2,m
MidStr>builddate,7,2,d
Let>FolderName=C:\
GetFileList>%FolderName%\*.doc,files
Separate>files,;,file_names
Let>k=0
Repeat>k
Let>k=k+1
GetFileDate>thisdate
If>%thisdate%= m/d/y,CopyIt
Until>k,file_names_count
SRT>CopyIt
CopyFile>%FolderName%\file_names_%k%,C:\DateTest
-
support
- Automation Wizard
- Posts: 1450
- Joined: Sat Oct 19, 2002 4:38 pm
- Location: London
-
Contact:
Post
by support » Thu Dec 16, 2004 10:41 am
Use GetFileList on your filespec, then Separate. Then a loop with GetFileDate. Compare filedate with the date in question.
You seem to be doing this to a point but I'm not sure what you're trying to do with FileDate>c:\*.doc,buildate - that won't work. FileDate can't take a wildcard. If it could which date should it return?
-
Captive
- Macro Veteran
- Posts: 213
- Joined: Sun Oct 20, 2002 8:37 pm
- Location: Colorado, USA
Post
by Captive » Thu Dec 16, 2004 2:41 pm
Here's something you may find useful... a VBScript snippet to return yesterdays date.
VBSTART
VBEND
VBEval>DateAdd("d",-1,date()),strOldDate
Message>%strOldDate%
You can then midstr the resulting %strOldDate%. It works correctly at the start of the month/year too.
-
BlackWisdom
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
Post
by BlackWisdom » Thu Dec 16, 2004 4:40 pm
Thnaks guys , hey is GetFileDate available in ver 7.2.05 - I dont see it -
-
support
- Automation Wizard
- Posts: 1450
- Joined: Sat Oct 19, 2002 4:38 pm
- Location: London
-
Contact:
Post
by support » Thu Dec 16, 2004 4:58 pm
Sorry, FileDate, not GetFileDate. Yes, FileDate is in 7.2.
-
BlackWisdom
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
Post
by BlackWisdom » Thu Dec 16, 2004 4:58 pm
Guys Im so close I can taste it..
VBSTART
VBEND
VBEval>DateAdd("d",-1,date()),strOldDate
Message>%strOldDate%
Month>MM
Day>DD
Year>YYYY
GetFileList>c:\*.doc,files
Separate>files,;,file_names
Let>k=0
Repeat>k
Let>k=k+1
GetFileDate>thisdate
If>%thisdate%=%strOldDate%,CpyFile
Until>k,file_names_count
Label>CpyFile
CopyFile>%thisdate%.doc,C:\DateTest
-
support
- Automation Wizard
- Posts: 1450
- Joined: Sat Oct 19, 2002 4:38 pm
- Location: London
-
Contact:
Post
by support » Thu Dec 16, 2004 5:22 pm
Hi,
It would help if you explain the problem so that we know how to help instead of just pasting code in the hope that we will immediately know which part is wrong.
However, I can see the following problems in your script:
1) It is FileDate NOT GetFileDate as per my previous post.
2) You have ommitted the filename from FileDate so it doesn't know which file to get the date for
3) in CopyFile you are trying to copy a file called DATE.doc to the new folder. This file doesn't exist. The file hasn't suddenly changed it's name to it's filedate.
4) You jump out of your loop if the date matches so it would only work for one file
Your loop should probably look something like this:
Let>k=0
Repeat>K
FileDate>file_names_%k%,fdate
If>fdate=strOldDate,CpyFile
Goto>continue
Label>CpyFile
CopyFile>file_names_%k%,c:\datetest
Label>continue
Until>k,file_names_count
This is untested. Hopefully it will help you understand what you were doing wrong and get you on the road to success!
-
BlackWisdom
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
Post
by BlackWisdom » Thu Dec 16, 2004 5:50 pm
Thanks for the quick reply, I will make a point in the future to explaion in detail what Im attempting to do, Im getting a Label error in the "Repeat K" entry of the code - its looking for the label . Often I use this loop and sometime it errors and sometime it does not in both instances the Label for K is not there - can you advise me as to what causes the error not to be generated on some instances?? Also what Im trying to do is backup files for a specific extension (any extension) that was created in the last 24 hours. Once I understand the logic I can modify it for differnt time periods. Here ie what I have so far:
VBSTART
VBEND
VBEval>DateAdd("d",-1,date()),strOldDate
Message>%strOldDate%
Month>MM
Day>DD
Year>YYYY
GetFileList>c:\*.doc,files
Separate>files,;,file_names
Let>k=0
Repeat>K
FileDate>file_names_%k%,fdate
If>fdate=strOldDate,CpyFile
Goto>continue
Label>CpyFile
CopyFile>file_names_%k%,c:\datetest
Label>continue
Until>k,file_names_count
-
support
- Automation Wizard
- Posts: 1450
- Joined: Sat Oct 19, 2002 4:38 pm
- Location: London
-
Contact:
Post
by support » Thu Dec 16, 2004 5:55 pm
You have Repeat>K but Until>k, - you are mixing case. Change Repeat>K to Repeat>k. Also make sure you do Edit/Remove Trailing Spaces in case there is a space on the end of the Repeat>k line.
-
Captive
- Macro Veteran
- Posts: 213
- Joined: Sun Oct 20, 2002 8:37 pm
- Location: Colorado, USA
Post
by Captive » Thu Dec 16, 2004 6:22 pm
Something else too:
%strOldDate% is in the format MM/DD/YYYY (on my PC).
(Edit: If yours is a different format, you may wish to adjust the "Let>sDateMask=...." line)
FileDate returns in the format YYYYMMDD (according to the help file).
So to compare the 2 (if blah=blah) you'll need to adjust a little, something like:
VBSTART
VBEND
VBEval>DateAdd("d",-1,date()),strOldDate
Rem>'This stores my date in %strOldDate% as 12/15/2004
Separate>%strOldDate%,/,lDate
Rem>'This splits so:
Rem>' %lDate_1% is 12
Rem>' %lDate_2% is 15
Rem>' %lDate_3% is 2004
Let>sDateMask=%lDate_3%%lDate_1%%lDate_2%
Rem>' My %sDateMask% should now be 20041215
MessageModal>Mask: %sDateMask%
You can remove the REM's and MESSAGE lines - I used them for debugging and to show you what's going on.
If you use the above method, and the loop support posted, you may want to use:
If>%fdate%=%sDateMask%,CpyFile
-
Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
-
Contact:
Post
by Bob Hansen » Thu Dec 16, 2004 7:11 pm
I believe that the *Date> commands are returned in the date format defined by the system.
This could be a problem if the script is going to be used on multiple systems.
In that case you may want to do a check for date format with different routines based on system settings. I suspect that it may be possible to pick up the date format from a registry location vs. testing for length, leading zeros in day/month, 2/4 digit years, etc.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
-
support
- Automation Wizard
- Posts: 1450
- Joined: Sat Oct 19, 2002 4:38 pm
- Location: London
-
Contact:
Post
by support » Thu Dec 16, 2004 7:20 pm
Or use VBScripts date format functions to return the format you desire based on any valid date format. Read the VBScript documentation. You can get it from
http://www.mjtnet.com/resources.htm