NewestFile only for visible?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
toopnad
Junior Coder
Posts: 34
Joined: Mon Apr 12, 2021 10:10 am
Location: Russian Totalitarian Republic, Perm city

NewestFile only for visible?

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

User avatar
Grovkillen
Automation Wizard
Posts: 998
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: NewestFile only for visible?

Post by Grovkillen » Wed Apr 14, 2021 3:19 pm

Get the attributes of the file.

Code: Select all

oFile.Attributes
https://docs.microsoft.com/en-us/office ... s-property
Let>ME=%Script%

Running: 15.0.24
version history

toopnad
Junior Coder
Posts: 34
Joined: Mon Apr 12, 2021 10:10 am
Location: Russian Totalitarian Republic, Perm city

Re: NewestFile only for visible?

Post by toopnad » Thu Apr 15, 2021 8:33 am

:oops: :oops:
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

Re: NewestFile only for visible?

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

User avatar
Grovkillen
Automation Wizard
Posts: 998
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: NewestFile only for visible?

Post by Grovkillen » Fri Apr 16, 2021 1:41 pm

Get the attribute first and only do the diff check if the value is below 2...?

https://docs.microsoft.com/en-us/office ... r-function

By the way, can't you do this with MS commands?
Let>ME=%Script%

Running: 15.0.24
version history

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