File modified help [need date AND time]

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

File modified help [need date AND time]

Post by Rain » Fri Mar 17, 2006 5:38 pm

Is it possible to find out the date and time a file was modified?
I'm working on a script that will backup all my scripts (.scp only) every time the macros.dat file in the C:\Program Files\MJT Net Ltd\Macro Scheduler directory is modified. All I can find is the FileDate command which is not helping me with what I would like to do.

There have been times I've worked on a very large script and modified quiet a bit just to find out the changes I made didn't fix my problems but made things worse and I couldn't remember what exactly I changed. I know what some of you may say "why not backup the script before you start modifying it?" Of course that would work but instead of having to do it manually I would much rather have it automated. Right now each backup will be created in a date and time stamped backup folder.

Sometimes the modified script works great after it has been modified 2 or 3 times but after modifying it 5 more times things gotten worse and I would like to go back to when it worked to my satisfaction. Having a script automatically back up all my scripts every time the macros.dat is modified would give me a piece of mind knowing I can always go back to when the script worked best after modification number 3, 4 or 5. Plus I don't have to figure what "bad" changes to remove which is almost impossible if you modify scripts 10,000 lines plus.

Thanks you for any help or suggestion.
Last edited by Rain on Fri Mar 17, 2006 5:54 pm, edited 1 time in total.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Mar 17, 2006 5:53 pm

I think IfFileChanged> will do what you ask.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Mar 17, 2006 6:01 pm

Me_again wrote:I think IfFileChanged> will do what you ask.
Thanks for your reply Me_Again but If I understand the help file on IfFileChanged correctly it will not read the time only the date. :?
IfFileChanged>filename,range[,label_name[,false_label_name]]

statements

[ [Else

else statements]

Endif ]

If the given file's date is in the range of days specified the first statements are executed, otherwise the else statements are executed. Alternatively, instead of Else/Endif specify label names.

When label names are specified execution jumps to the specified label if the given file's date is in the range of days specified. If a second false label is specified, execution will jump to that label if the expression resolves false. Subroutine names can also be specified. When specifying a subroutine name execution will jump to that subroutine and return to the line after the If statement when the subroutine has completed.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Mar 17, 2006 6:25 pm

I believe that's correct, backup to me is a daily thing but after posting I did wonder if you were thinking of doing it more often.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Mar 17, 2006 7:27 pm

Ok, let's try again, I'm just getting my feet wet with vbscript but filesystemobject seems to be what will work (this script adapted from this kpassaur/admin thread http://www.mjtnet.com/forum/viewtopic.p ... stmodified )

Iffileexists>C:\test\test.txt,continue,error
Label>continue

VBSTART

Function filedate (filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = f.DateLastModified
s = FormatDateTime(s,vbShortDate)
filedate = s
End Function
Function filetime (filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = f.DateLastModified
s = FormatDateTime(s,vbShortTime)
filetime = s
End Function


VBEND

Let>filetest=C:\test\test.txt
VBEval>filetime("%filetest%"),modifiedtime
VBEval>filedate("%filetest%"),modifieddate
MessageModal>%modifiedtime% %modifieddate%
Goto>theend


Label>error
MDL>File doesn't exist

Label>theend

User avatar
JRL
Automation Wizard
Posts: 3502
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Mar 17, 2006 9:05 pm

Or for those of us who are VBScript challenged.


From DOS help for Dir:


DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

[drive:][path][filename]
Specifies drive, directory, and/or files to list.

/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files - Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
default. Use /-C to disable display of separator.
/D Same as wide but files are list sorted by column.
/L Uses lowercase.
/N New long list format where filenames are on the far right.
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order
/P Pauses after each screenful of information.
/Q Display the owner of the file.
/S Displays files in specified directory and all subdirectories.
/T Controls which time field displayed or used for sorting
timefield C Creation
A Last Access
W Last Written

/W Uses wide list format.
/X This displays the short names generated for non-8dot3 file
names. The format is that of /N with the short name inserted
before the long name. If no short name is present, blanks are
displayed in its place.
/4 Displays four-digit years


==============================================================================

Therefore:

If the file path\name is set to variable filename.

Let>RP_WAIT=1
Let>RP_WINDOWMODE=2
Run>cmd /c dir %filename% /T:W | find "%filename%" > c:\~dirfindmodtime~
Readln>c:\~dirfindmodtime~,1,line
Midstr>line,1,10,FileModDate
Midstr>line,14,7,FileModTime
Deletefile>c:\~dirfindmodtime~


Later,
Dick

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sat Mar 18, 2006 1:30 pm

Thanks Dick and Me_Again I really appreciate your replies and tips.

I've decided to go with VB Script and changed "s = FormatDateTime(s,vbShortTime)" to "s = FormatDateTime(s,vbLongTime)" to have it include seconds as well.

Here is the finished script with Dialog.

let>APP_TITLE=Automated Script Backup
let>MJT_Net_Folder_Location=C:\Program Files\MJT Net Ltd\Macro Scheduler
let>Backup_Folder_Location=C:\Backup Scripts
Let>Macros_Dat_File_Location=C:\Program Files\MJT Net Ltd\Macro Scheduler\macros.dat
cre>%Backup_Folder_Location%
vbstart
Function filetime (filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = f.DateLastModified
s = FormatDateTime(s,vbLongTime)
filetime = s
End Function
vbend
Dialog>Dialog1
Caption=Script Backup
Width=155
Height=95
Top=CENTER
Left=CENTER
Max=0
Min=0
Close=1
Resize=0
Label= ,24,32,true
Button=Open Backup Folder,8,0,129,25,1
EndDialog>Dialog1

show>Dialog1
label>start
rda>Dialog1
vbeval>filetime("%Macros_Dat_File_Location%"),time_a
fdt>%Macros_Dat_File_Location%,date_a
let>check_a=%time_a%%date_a%
label>loop
wai>0.005
gda>Dialog1,result
if>result=1,open folder
if>result=2,2
VBEval>filetime("%Macros_Dat_File_Location%"),time_b
fdt>%Macros_Dat_File_Location%,date_b
let>check_b=%time_b%%date_b%
if>check_bcheck_a,backup
goto>loop
label>backup
gfl>%MJT_Net_Folder_Location%\*.scp,files
sep>files,;,file_names
gtm>btime
let>Dialog1.msLabel0=%file_names_count% Scripts backed up at%crlf%%btime%
rda>Dialog1
let>file_counter=0
day>day
month>month
year>year
sec>seconds
min>minutes
hour>hour
let>folder_name=Backup %day%-%month%-%year% %hour%-%minutes%-%seconds%
cre>%Backup_Folder_Location%\%folder_name%
repeat>file_counter
Let>file_counter=file_counter+1
cop>file_names_%file_counter%,%Backup_Folder_Location%\%folder_name%\
until>file_counter,file_names_count
goto>start
label>open folder
exe>C:\Backup Scripts
goto>start
label>2
Here is the same script without Dialog

let>APP_TITLE=Automated Script Backup
let>MJT_Net_Folder_Location=C:\Program Files\MJT Net Ltd\Macro Scheduler
let>Backup_Folder_Location=C:\Backup Scripts
Let>Macros_Dat_File_Location=C:\Program Files\MJT Net Ltd\Macro Scheduler\macros.dat
cre>%Backup_Folder_Location%
vbstart
Function filetime (filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = f.DateLastModified
s = FormatDateTime(s,vbLongTime)
filetime = s
End Function
vbend
label>start
vbeval>filetime("%Macros_Dat_File_Location%"),time_a
fdt>%Macros_Dat_File_Location%,date_a
let>check_a=%time_a%%date_a%
label>loop
wai>0.005
VBEval>filetime("%Macros_Dat_File_Location%"),time_b
fdt>%Macros_Dat_File_Location%,date_b
let>check_b=%time_b%%date_b%
if>check_bcheck_a,backup
goto>loop
label>backup
gfl>%MJT_Net_Folder_Location%\*.scp,files
sep>files,;,file_names
let>file_counter=0
day>day
month>month
year>year
sec>seconds
min>minutes
hour>hour
let>folder_name=Backup %day%-%month%-%year% %hour%-%minutes%-%seconds%
cre>%Backup_Folder_Location%\%folder_name%
repeat>file_counter
Let>file_counter=file_counter+1
cop>file_names_%file_counter%,%Backup_Folder_Location%\%folder_name%\
until>file_counter,file_names_count
goto>start

alanimal
Junior Coder
Posts: 40
Joined: Thu Jun 09, 2005 11:57 pm

Post by alanimal » Wed Jun 07, 2006 11:41 pm

Hi Guys,

I am looking for help to create a script very similar to this.

Basically i have a set of folders which contain files that have been processed by an agent writing data to an sql db. These files are *.eml files and these folders are updated with new files at a rate of approximately 10 per second.

What i would like to do, is scan the folders and if each folder has a file that has been modified within the last 90 minutes, then just to display to screen something like this:

_________________________________________
Current Time: 08 June 2006 11:26AM
Folder: Mod Date:

CHS 08 June 2006 11:20AM
DAR 08 June 2006 11:21AM
COB 08 June 2006 11:26AM
DIA 08 June 2006 11:25AM
__________________________________________

As you can see it displays the date and time, the folder scanned and the timestamp for the last message received.

The above shows that messages have been coming through without any problems. And below is what I would like to display if there is a problem:
_________________________________________
Current Time: 08 June 2006 11:26AM
Folder: Mod Date:

CHS 08 June 2006 11:20AM
DAR 08 June 2006 11:21AM
COB 08 June 2006 08:26AM ERROR! NO MESSAGES FOR 180 minutes.
DIA 08 June 2006 11:25AM
__________________________________________

As you can see it has picked up that no messages have come through to the \\COB\ folder for 3 hours, so we display the alert to screen and using an SMTP command an email is sent to let the appropriate people know that no data is coming in from the COB system.

All the folders containing these files are in the same directory.

If anyone could shed any light on a script that would be capable of doing this it would be so appreciated!

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Clip

Post by kpassaur » Mon Mar 02, 2009 7:44 pm

If using the dir command as mentioned above there is a utility called clip.exe that is being shipped with Vista and I believe with server 2003. If I recall I got it with the Windows Resource toolkit or something like that. XP does not have it. Anyway it allows command line output to be directed to the clipboard as opposed to a text file.

In a nutshell it makes the dir example easier as you don't even have to write and then read the file, just get it from the clipboard. This is also very useful if you don't want to create any temp files, I used it to detect if Acrobat was present on a PC when an autorun CD was installed.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Clip

Post by jpuziano » Tue Mar 03, 2009 12:22 am

kpassaur wrote:If using the dir command as mentioned above there is a utility called clip.exe that is being shipped with Vista and I believe with server 2003. If I recall I got it with the Windows Resource toolkit or something like that. XP does not have it. Anyway it allows command line output to be directed to the clipboard as opposed to a text file.
Hi kpassaur,

Thanks for that tip. For XP Professional users that would like to try clip.exe, I see its available from a link on the following page: http://blogs.techrepublic.com.com/windo ... ows/?p=521

I assume its the server 2003 version of clip.exe as the Vista version reportedly will not work with XP.

I have not tried it... scan for viruses before trying it of course... but if you do try it and it works for you... let us know your findings.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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