folderIdx question

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
EBrant
Posts: 99
Joined: Thu Feb 02, 2012 1:51 am

folderIdx question

Post by EBrant » Sat Jul 21, 2012 4:12 am

Hello All :)Can someone please help me with the following question. I have the script below.Now lets say I have one file in the C:Ernie directory called OldFile.datthis script works and logs an event on the windows event log about the .DAT file being (being over 35 minutes old). I also have a .EDI file in the C:Ernie directory which is ignores. For example where I enter WScript.Echo ValueFileType it just shows the DAT file.Now if I add for each file in fileWscript.Echo File.Namenextabove "For Each folderIdx In Files" then I get all the files listed. I is below this line that only the DAT files is listed.I toke this script off of the internet (as learning powershell at the moment and not really looked at vbscript). can someone please tell me what folderIdx means please?also if change the RegEx above to .Pattern = "EDI File|DAT File"it just lists DAT files still, however if I change to .Pattern = "EDI Fileit lists both DAT and EDI files (i.e. WScript.Echo ValueFileType) However I am not calling this RegEx at the point I am invoking WScript.Echo ValueFileType therefore I cannot see how this affects the output of WScript.Echo ValueFileType? basically I wanted to use RegEx expression the say match DAT File or EDI file which is why I used the expression I did. Then check all files in the specified directory (not sub directory) for any files over X age.Thanks all in advanceErnieSet objRE = New RegExpWith objRE .Pattern = "DAT File|EDI File" .IgnoreCase = True .Global = FalseEnd WithSet oFso = CreateObject("Scripting.FileSystemObject")Set oFolder = oFSO.GetFolder(FolderName)Set Files = oFolder.FilesIf Files.Count < 1 Then'WScript.Echo "No Files Exist"WScript.QuitEnd IfFor Each folderIdx In FilesSet objFile = oFso.GetFile(folderIdx)ValueMinutesAgo=DateDiff("n",objFile.DateLastModified,Now)ValueFileType=objFile.TypeValueFileName=objFile.NameWScript.Echo ValueFileTypeEventDescription = "The file name is " & ValueFileName & " which is " & ValueMinutesAgo & " minutes old"If (objRE.Test( ValueFileType ) And ValueMinutesAgo > 35) Then'WScript.Echo "File is older than 35 minutes"WshShell.LogEvent 8, EventDescriptionWScript.QuitEnd IfNext

User avatar
EBrant
Posts: 99
Joined: Thu Feb 02, 2012 1:51 am

folderIdx question

Post by EBrant » Sat Jul 21, 2012 4:12 am

Hello All :)Can someone please help me with the following question. I have the script below.Now lets say I have one file in the C:Ernie directory called OldFile.datthis script works and logs an event on the windows event log about the .DAT file being (being over 35 minutes old). I also have a .EDI file in the C:Ernie directory which is ignores. For example where I enter WScript.Echo ValueFileType it just shows the DAT file.Now if I add for each file in fileWscript.Echo File.Namenextabove "For Each folderIdx In Files" then I get all the files listed. I is below this line that only the DAT files is listed.I toke this script off of the internet (as learning powershell at the moment and not really looked at vbscript). can someone please tell me what folderIdx means please?also if change the RegEx above to .Pattern = "EDI File|DAT File"it just lists DAT files still, however if I change to .Pattern = "EDI Fileit lists both DAT and EDI files (i.e. WScript.Echo ValueFileType) However I am not calling this RegEx at the point I am invoking WScript.Echo ValueFileType therefore I cannot see how this affects the output of WScript.Echo ValueFileType? basically I wanted to use RegEx expression the say match DAT File or EDI file which is why I used the expression I did. Then check all files in the specified directory (not sub directory) for any files over X age.Thanks all in advanceErnieSet objRE = New RegExpWith objRE .Pattern = "DAT File|EDI File" .IgnoreCase = True .Global = FalseEnd WithSet oFso = CreateObject("Scripting.FileSystemObject")Set oFolder = oFSO.GetFolder(FolderName)Set Files = oFolder.FilesIf Files.Count < 1 Then'WScript.Echo "No Files Exist"WScript.QuitEnd IfFor Each folderIdx In FilesSet objFile = oFso.GetFile(folderIdx)ValueMinutesAgo=DateDiff("n",objFile.DateLastModified,Now)ValueFileType=objFile.TypeValueFileName=objFile.NameWScript.Echo ValueFileTypeEventDescription = "The file name is " & ValueFileName & " which is " & ValueMinutesAgo & " minutes old"If (objRE.Test( ValueFileType ) And ValueMinutesAgo > 35) Then'WScript.Echo "File is older than 35 minutes"WshShell.LogEvent 8, EventDescriptionWScript.QuitEnd IfNext

User avatar
EBrant
Posts: 99
Joined: Thu Feb 02, 2012 1:51 am

folderIdx question

Post by EBrant » Sat Jul 21, 2012 4:23 am

I think I may of figured it out, it the WScript.Quit causing me issues! I will see how I get on now.... :)

Locked