Hints, tips and tricks for newbies
Moderators: Dorian (MJT support), JRL
-
toopnad
- Junior Coder
- Posts: 34
- Joined: Mon Apr 12, 2021 10:10 am
- Location: Russian Totalitarian Republic, Perm city
Post
by toopnad » Wed Apr 14, 2021 2:37 pm
How can I change the function to only work for visible files?
Code: Select all
Function NewestFile(Folder)
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(Folder)
dPrevDate = "0"
For each oFile In oFolder.Files
If DateDiff("s", dPrevDate, oFile.DateLastModified) > 0 Then
sNewestFile = oFile.Path
dPrevDate = oFile.DateLastModified
End If
Next
NewestFile = sNewestFile
End Function
-
Grovkillen
- Automation Wizard
- Posts: 1131
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
-
Contact:
Post
by Grovkillen » Wed Apr 14, 2021 3:19 pm
-
toopnad
- Junior Coder
- Posts: 34
- Joined: Mon Apr 12, 2021 10:10 am
- Location: Russian Totalitarian Republic, Perm city
Post
by toopnad » Thu Apr 15, 2021 8:33 am
Last edited by
toopnad on Fri Apr 16, 2021 7:05 am, edited 1 time in total.
-
toopnad
- Junior Coder
- Posts: 34
- Joined: Mon Apr 12, 2021 10:10 am
- Location: Russian Totalitarian Republic, Perm city
Post
by toopnad » Thu Apr 15, 2021 8:33 am
I think you are absolutely right, but my inexperience prevents me from fully understanding the syntax of the language. Tell me how to write correctly?
Code: Select all
Function NewestFile(Folder)
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(Folder)
dPrevDate = "0"
For Each oFile.attributes IsNot 2 In oFolder.Files
If DateDiff("s", dPrevDate, oFile.DateLastModified) > 0 Then
sNewestFile = oFile.Path
dPrevDate = oFile.DateLastModified
End If
Next
NewestFile = sNewestFile
End Function
Please help to understand