![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | file object help requested Hi, My script requirements (final steps) are to access a root folder on a drive specified by the user and search for subfolders. For each subfolder, I am required to check for text files, and MsgBox if there are none. If there ARE text files, I am required to open a MsgBox for each sub-folder displaying the name of each text file and its associated file size (1 msgbox for each sub-folder containing text files). I am thinking of a loop within a loop if possible, but do not know the syntax to use to access the drive's root folder, sub-folders, and associated files to test for text 'type'. Half-baked pseudo code/real code in my mind looks like this: for each sub-folder in root folder if text files count = 0 Then MsgBox "No text files found" else for each file in sub-folder(x) if file is text file Then mssg = mssg & textfile(x).name & textfile(x).size & VbCrLf next MsgBox mssg mssg = "" next ____________________________________________________________ and my current script looks like this: Option Explicit 'Declare Variables Dim WshShl, iconyn, dtop, scut, dltr, argobj, fso, dready Dim path, fold, subf 'Get User Input For Desktop Icon Creation set WshShl = WScript.CreateObject("WScript.Shell") iconyn = WshShl.Popup("Would you like a shortcut for this script"_ & " created on your desktop?",,"User Input",36) 'Process User Selection and Create Icon If Requested If iconyn = 6 Then dtop = WshShl.SpecialFolders("Desktop") set scut = WshShl.CreateShortcut(dtop & "\textchk.lnk") scut.TargetPath = "c:\textchk.vbs" scut.IconLocation = "c:\disk.ico" scut.Save End if 'Get user input for Drive letter selection dltr = InputBox("Please enter a drive letter") 'Check for existance of drive and if it is ready Set fso = WScript.CreateObject("Scripting.filesystemobject") If Not fso.DriveExists(dltr) Then Wscript.Echo "That Drive does not Exist" Wscript.Quit End If Set dready = fso.GetDrive(dltr) If Not (dready.IsReady) Then Wscript.Echo "That Drive Is Not Ready" Wscript.Quit End If 'Check for existance of sub folders set fold = fso.GetFolder(dltr & ":") set subf = fold.subfolders If subf.count =0 Then Wscript.echo "The Selected Drive Contains No Sub-Folders" Wscript.Quit End If 'Produce output for subfolders containing text files |
My System Specs![]() |
| | #2 (permalink) |
| | Re: file object help requested "Vgolfmaster" <Vgolfmaster@xxxxxx> wrote in message news:098E7367-3CB4-4EAF-9468-E1BE36B2635A@xxxxxx Quote: > Hi, > > My script requirements (final steps) are to access a root folder on a > drive > specified by the user and search for subfolders. For each subfolder, I am > required to check for text files, and MsgBox if there are none. If there > ARE > text files, I am required to open a MsgBox for each sub-folder displaying > the > name of each text file and its associated file size (1 msgbox for each > sub-folder containing text files). I am thinking of a loop within a loop > if > possible, but do not know the syntax to use to access the drive's root > folder, sub-folders, and associated files to test for text 'type'. > > Half-baked pseudo code/real code in my mind looks like this: > > for each sub-folder in root folder > if text files count = 0 Then > MsgBox "No text files found" > else > for each file in sub-folder(x) > if file is text file Then > mssg = mssg & textfile(x).name & textfile(x).size & VbCrLf > next > MsgBox mssg > mssg = "" > next > ____________________________________________________________ > and my current script looks like this: > > Option Explicit > > 'Declare Variables > Dim WshShl, iconyn, dtop, scut, dltr, argobj, fso, dready > Dim path, fold, subf > > 'Get User Input For Desktop Icon Creation > > set WshShl = WScript.CreateObject("WScript.Shell") > > iconyn = WshShl.Popup("Would you like a shortcut for this script"_ > & " created on your desktop?",,"User Input",36) > > 'Process User Selection and Create Icon If Requested > > If iconyn = 6 Then > dtop = WshShl.SpecialFolders("Desktop") > set scut = WshShl.CreateShortcut(dtop & "\textchk.lnk") > scut.TargetPath = "c:\textchk.vbs" > scut.IconLocation = "c:\disk.ico" > scut.Save > End if > > 'Get user input for Drive letter selection > > dltr = InputBox("Please enter a drive letter") > > 'Check for existance of drive and if it is ready > > Set fso = WScript.CreateObject("Scripting.filesystemobject") > If Not fso.DriveExists(dltr) Then > Wscript.Echo "That Drive does not Exist" > Wscript.Quit > End If > Set dready = fso.GetDrive(dltr) > If Not (dready.IsReady) Then > Wscript.Echo "That Drive Is Not Ready" > Wscript.Quit > End If > > 'Check for existance of sub folders > > set fold = fso.GetFolder(dltr & ":") > set subf = fold.subfolders > If subf.count =0 Then > Wscript.echo "The Selected Drive Contains No Sub-Folders" > Wscript.Quit > End If > 'Produce output for subfolders containing text files Set oFSO = CreateObject("Scripting.FileSystemObject") Set cSubf = oFSO.GetFolder(dltr & ":\").SubFolders If cSubf.count = 0 Then WScript.echo "The Selected Drive Contains No Sub-Folders" WScript.Quit Else For Each oFolder In cSubf WScript.Echo "Processing", oFolder.Path For Each oFile In oFolder.Files WScript.Echo oFile.Name Next Next End If |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Could not add the requested feature. The error is: The system cannot find the file sp | Network & Sharing | |||
| How to use measure-object against multiple file types | PowerShell | |||
| Compare-Object and Get the name of object/File? | PowerShell | |||
| Exporting an object to a csv file | PowerShell | |||
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | PowerShell | |||