ignore files that start with _ or .

Microsoft Windows 7 ultimate 32-bit
March 15, 2010 at 12:42:33
Specs: Windows XP
I am trying to write a vb script that search for folders and subfolders for files older than 10 minutes but ignore the files if they start with _ or dot (.). How can I do this? here is my script:
====
Set WshShell = CreateObject("WScript.Shell")

Dim fso, dTwoWeeksAgo, dTenMinutesAgo, dCurrentTime

dCurrentTime=Now

dTenMinutesAgo=DateAdd("n", -10, dCurrentTime)

wscript.echo dTenMinutesAgo

Set fso = CreateObject("Scripting.FileSystemObject")

DirWalk("c:\tps\")
Sub DirWalk(parmPath)
Dim oSubDir, oSubFolder, oFile, n

On Error Resume Next

Set oSubFolder = fso.getfolder(parmPath)

For Each oFile In oSubFolder.Files ' look in the current dir

'ElseIf DateAdd("n", -10, dCurrentTime) > oFile.DateLastModified Then


if (oFile.Name.startswith("."))then


W
WshShell.LogEvent 1, oFile.Path & " is older than 10 minutes, escalate"

end if

'End If
Next

For Each oSubDir In oSubFolder.Subfolders

wscript.echo "folder name" & oSubdir.Path

DirWalk oSubDir.Path

Next

On Error Goto 0

End Sub
======


See More: ignore files that start with _ or .

Report •


#1
March 15, 2010 at 12:46:19
this is not a programing forum please ask your question in the appropiate forum

Davidw


Report •

#2
March 15, 2010 at 22:18:29
you have the right idea, almost worked. here is what i did:

public osubdir, osubfolder, ofile, n
public fso, dTwoWeeksAgo, dTenMinutesAgo
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
set ff=fso.createtextfile("test.out",2)
dTenMinutesAgo=DateAdd("n", -10, Now)
wscript.echo dTenMinutesAgo
DirWalk("c:\comands\")
msgbox "done"
wscript.quit

Sub DirWalk(parmPath)
'On Error Resume Next
Set oSubFolder = fso.getfolder(parmPath)
For Each oFile In oSubFolder.Files
' look in the current dir
'just for analysis
ff.writeline ofile&" "&ofile.datelastmodified&" -- "&dtenminutesago
test=left(oFile.Name,1)
if instr("._",test)=0 then
If dtenminutesago > oFile.DateLastModified Then
ff.writeline ofile&" "&ofile.datelastmodified&" ** "&dtenminutesago
WshShell.LogEvent 1, oFile.Path & " is older than 10 minutes, escalate"
end if
end if
Next
For Each oSubDir In oSubFolder.Subfolders
'wscript.echo "------- folder name" & oSubdir.Path
DirWalk oSubDir.Path
Next
On Error Goto 0
End Sub

i am ignorant of logevent, so i used a textfile instead.
also ignorant of "startswith", i got an object not recogn error,
so i used "left()" instead.
I think it's good practice to put the "global" artillery at the top (f/e: objects wscript.shell, fso, and all shared variables) instead of down in code. I almost never disable error-trapping unless i expect an error, then code it carefully (i HATE errortrapping but it is necessary evil). Ht.helps.


Report •

#3
March 16, 2010 at 06:54:42
thank you so much. I have one more question. Under this directory : DirWalk("c:\comands\"), there is a sub directory that starts with underscore (_) that I would like to ignore as well. How can I skipp the sub folder that starts with _?

thank you so much for your help with this.


Report •

Related Solutions

#4
March 16, 2010 at 09:57:38
same idea:
For Each oSubDir In oSubFolder.Subfolders
test=left(osubdir.path,1)
if test<>"_" then
DirWalk oSubDir.Path
end if
Next


Report •

#5
March 16, 2010 at 10:34:52
thanks again.

Report •


Ask Question