Help ! I want read always the last report saved
Moderators: JRL, Dorian (MJT support)
Help ! I want read always the last report saved
I want read always the last report saved and send to a variable. These reports are saved all time. Example:
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 15.10.txt
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 16.11.txt
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 16.35.txt
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 22.10.txt
In this case i want read: Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 22.10.txt and store in a variable to use string functions later.
Ty for your time
Regards
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 15.10.txt
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 16.11.txt
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 16.35.txt
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 22.10.txt
In this case i want read: Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 22.10.txt and store in a variable to use string functions later.
Ty for your time
Regards
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
The last report saved should have a later file date than the rest, so you shouldn't need to parse the file names, and should just be able to use this script here:
http://www.mjtnet.com/forum/viewtopic.php?t=1462
This finds the last file in a directory based on its file date. You shouldn't need to parse the file names.
If I am wrong in your case then we could still write code to parse the file names and work out the latest based on the date and time portions of the name. Let me know if the above doesn't work and I can help you with this instead.
http://www.mjtnet.com/forum/viewtopic.php?t=1462
This finds the last file in a directory based on its file date. You shouldn't need to parse the file names.
If I am wrong in your case then we could still write code to parse the file names and work out the latest based on the date and time portions of the name. Let me know if the above doesn't work and I can help you with this instead.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
There are others files in directory.
I want parse the names , but i want take just the main line ignoring the date and hour in name. Then i take the most updated file with "Updated Report - 'xxxxxxxx'" in name and read the file.
Example:
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 15.10.txt
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 17.11.txt
Last Sales - 'Truck Sales' - Date 2006.7.22 - Hour 14.11.txt
Last Sales - 'Truck Sales' - Date 2006.7.22 - Hour 18.19.txt
Last Acquisitions - 'Motorbike' - Date 2006.7.22 - Hour 12.10.txt
Last Acquisitions - 'Motorbike' - Date 2006.7.22 - Hour 14.10.txt
I want read and store into a variable the most updated:
Updated Report - 'Car Sales' - XXXXXX.txt
Last Sales - 'Truck Sales' - XXXXXXX.txt
Last Acquisitions - 'Motorbike' - XXXXXXX.txt
I want parse the names , but i want take just the main line ignoring the date and hour in name. Then i take the most updated file with "Updated Report - 'xxxxxxxx'" in name and read the file.
Example:
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 15.10.txt
Updated Report - 'Car Sales' - Date 2006.7.22 - Hour 17.11.txt
Last Sales - 'Truck Sales' - Date 2006.7.22 - Hour 14.11.txt
Last Sales - 'Truck Sales' - Date 2006.7.22 - Hour 18.19.txt
Last Acquisitions - 'Motorbike' - Date 2006.7.22 - Hour 12.10.txt
Last Acquisitions - 'Motorbike' - Date 2006.7.22 - Hour 14.10.txt
I want read and store into a variable the most updated:
Updated Report - 'Car Sales' - XXXXXX.txt
Last Sales - 'Truck Sales' - XXXXXXX.txt
Last Acquisitions - 'Motorbike' - XXXXXXX.txt
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Try this:
This uses a modified version of the function I linked to which also checks for a match against the file name. So you can call it with the directory and the identifying part of the file name. It will then return the latest file that contains that text in the file name.
Code: Select all
VBSTART
Function LastModified(folderspec,filespec)
Dim fso, f, f1, fc, s, lastfiledate, latestfile
lastfiledate = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
if InStr(f1.Name,filespec) > 0 then
If f1.DateLastModified > lastfiledate then
lastfiledate = f1.DateLastModified
latestfile = f1.Name
end if
end if
Next
LastModified = latestfile
End Function
VBEND
VBEval>LastModified("c:\some folder","Updated Report - 'Car Sales' -"),URCS
MessageModal>URCS
VBEval>LastModified("c:\some folder","Last Sales - 'Truck Sales' -"),LSTS
MessageModal>LSTS
VBEval>LastModified("c:\some folder","Last Acquisitions - 'Motorbike' -"),LAMB
MessageModal>LAMB
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Change f1.DateLastModified to f1.DateCreated:
Here I've also changed the function name to something more relevant.
Code: Select all
VBSTART
Function LastCreated(folderspec,filespec)
Dim fso, f, f1, fc, s, lastfiledate, latestfile
lastfiledate = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
if InStr(f1.Name,filespec) > 0 then
If f1.DateCreated > lastfiledate then
lastfiledate = f1.DateCreated
latestfile = f1.Name
end if
end if
Next
LastCreated = latestfile
End Function
VBEND
VBEval>LastCreated("c:\some folder","Updated Report - 'Car Sales' -"),URCS
MessageModal>URCS
VBEval>LastCreated("c:\some folder","Last Sales - 'Truck Sales' -"),LSTS
MessageModal>LSTS
VBEval>LastCreated("c:\some folder","Last Acquisitions - 'Motorbike' -"),LAMB
MessageModal>LAMB
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
The correct is:
VBSTART
Function LastCreated(folderspec,filespec)
Dim fso, f, f1, fc, s, lastfiledate, latestfile
lastfiledate = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
if InStr(f1.Name,filespec) > 0 then
If f1.DateCreated > lastfiledate then
If f1.DateLastModified >= lastfiledate then
lastfiledate = f1.DateLastModified
latestfile = f1.Name
End If
end if
end if
Next
LastCreated = latestfile
End Function
VBEND
VBEval>LastCreated("%PATH%","FILE%"),RESULT
VBSTART
Function LastCreated(folderspec,filespec)
Dim fso, f, f1, fc, s, lastfiledate, latestfile
lastfiledate = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
if InStr(f1.Name,filespec) > 0 then
If f1.DateCreated > lastfiledate then
If f1.DateLastModified >= lastfiledate then
lastfiledate = f1.DateLastModified
latestfile = f1.Name
End If
end if
end if
Next
LastCreated = latestfile
End Function
VBEND
VBEval>LastCreated("%PATH%","FILE%"),RESULT