![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Scanning multiple folders for files possible? Hello, I have very limited experience with vbs, so pardon me if the answer is obvious. I need to develop a script that would scan several directories for specific type of file, then scan the contents of those files, copy needed parts into another file and perform some work on it. I know that most of that is possible with vbs. However I can't find any way to force the script to scan multiple folders (some names are unicode). Ideally, the folders should be marked as "scanned" after the script finishes, or to maintain a list of scanned files, so that if the contents of the folder is modified, only the additional files would be scanned. The more general question is vbs the right tool for a job or should I use more advance language? And could someone share ideas on the scanning part? Thanks for help... |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Scanning multiple folders for files possible? "alm80" <alm80@xxxxxx> wrote in message news:5870BADE-B7FA-4DF9-86AD-754383BD4711@xxxxxx Quote: > Hello, > I have very limited experience with vbs, so pardon me if the answer is > obvious. I need to develop a script that would scan several directories > for > specific type of file, then scan the contents of those files, copy needed > parts into another file and perform some work on it. I know that most of > that > is possible with vbs. However I can't find any way to force the script to > scan multiple folders (some names are unicode). Ideally, the folders > should > be marked as "scanned" after the script finishes, or to maintain a list of > scanned files, so that if the contents of the folder is modified, only the > additional files would be scanned. > > The more general question is vbs the right tool for a job or should I use > more advance language? And could someone share ideas on the scanning part? > Thanks for help... It is easy to get VB Script to scan multiple folders but you need to be clear which of these options apply: a) Scan every folder that you specify in your script. b) Scan every subfolder of the specified folder, one level deep. c) Recursively scan every subfolder of the nominated folder. You also need to be clearer what you mean with "if the contents of the folder is modified, only the additional files would be scanned". Scanned when the code is run next time? Or scanned during the current run? The usual process goes like this: - Scan one folder - Move on to the next folder. - Scan it. - Continue until you run out of folders. The need to "mark" folders does not arise with this method - it simply processes every folder it finds, without repeating itself. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Scanning multiple folders for files possible? "Pegasus [MVP]" wrote: Quote: > VB Script is a highly appropriate language for this type of thing. > > It is easy to get VB Script to scan multiple folders but you need to be > clear which of these options apply: > a) Scan every folder that you specify in your script. > b) Scan every subfolder of the specified folder, one level deep. > c) Recursively scan every subfolder of the nominated folder. > > You also need to be clearer what you mean with "if the contents of the > folder is modified, only the additional files would be scanned". Scanned > when the code is run next time? Or scanned during the current run? The usual > process goes like this: > - Scan one folder > - Move on to the next folder. > - Scan it. > - Continue until you run out of folders. > The need to "mark" folders does not arise with this method - it simply > processes every folder it finds, without repeating itself. > > The task is to scan the folder and all the subfolders. The contents of the folders would not be modified during the scan, but can be different (some files added) at the next run. In most cases however the contents would not be modified ever, that means that once scanned and marked as scanned the folders would not need to be scanned anymore. Another problem is that many folders names use unicode non-latin characters. So far in my experiments, the script failed to recognize non-latin characters. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Scanning multiple folders for files possible? "alm80" <alm80@xxxxxx> wrote in message news:074717AA-F9C6-41CF-93DD-2446BE43E7D7@xxxxxx Quote: > > > "Pegasus [MVP]" wrote: > > Quote: >> VB Script is a highly appropriate language for this type of thing. >> >> It is easy to get VB Script to scan multiple folders but you need to be >> clear which of these options apply: >> a) Scan every folder that you specify in your script. >> b) Scan every subfolder of the specified folder, one level deep. >> c) Recursively scan every subfolder of the nominated folder. >> >> You also need to be clearer what you mean with "if the contents of the >> folder is modified, only the additional files would be scanned". Scanned >> when the code is run next time? Or scanned during the current run? The >> usual >> process goes like this: >> - Scan one folder >> - Move on to the next folder. >> - Scan it. >> - Continue until you run out of folders. >> The need to "mark" folders does not arise with this method - it simply >> processes every folder it finds, without repeating itself. >> >> > The task is to scan the folder and all the subfolders. The contents of the > folders would not be modified during the scan, but can be different (some > files added) at the next run. In most cases however the contents would not > be > modified ever, that means that once scanned and marked as scanned the > folders would not need to be scanned anymore. Another problem is that > many > folders names use unicode non-latin characters. So far in my experiments, > the > script failed to recognize non-latin characters. Set oFSO = CreateObject("Scripting.FileSystemObject") sFolder = "d:\Sat" Set oParent = oFSO.GetFolder(sFolder) For Each oFolder In oParent.SubFolders WScript.Echo oFolder.Name Next |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Scanning multiple folders for files possible? "Pegasus [MVP]" wrote: Quote: > > Try this code fragment: > Set oFSO = CreateObject("Scripting.FileSystemObject") > sFolder = "d:\Sat" > Set oParent = oFSO.GetFolder(sFolder) > For Each oFolder In oParent.SubFolders > WScript.Echo oFolder.Name > Next > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Scanning multiple folders for files possible? "alm80" <alm80@xxxxxx> wrote in message news:074717AA-F9C6-41CF-93DD-2446BE43E7D7@xxxxxx Quote: > > > "Pegasus [MVP]" wrote: > > Quote: >> VB Script is a highly appropriate language for this type of thing. >> >> It is easy to get VB Script to scan multiple folders but you need to be >> clear which of these options apply: >> a) Scan every folder that you specify in your script. >> b) Scan every subfolder of the specified folder, one level deep. >> c) Recursively scan every subfolder of the nominated folder. >> >> You also need to be clearer what you mean with "if the contents of the >> folder is modified, only the additional files would be scanned". Scanned >> when the code is run next time? Or scanned during the current run? The >> usual >> process goes like this: >> - Scan one folder >> - Move on to the next folder. >> - Scan it. >> - Continue until you run out of folders. >> The need to "mark" folders does not arise with this method - it simply >> processes every folder it finds, without repeating itself. >> >> > The task is to scan the folder and all the subfolders. The contents of the > folders would not be modified during the scan, but can be different (some > files added) at the next run. In most cases however the contents would not > be > modified ever, that means that once scanned and marked as scanned the > folders would not need to be scanned anymore. Another problem is that > many > folders names use unicode non-latin characters. So far in my experiments, > the > script failed to recognize non-latin characters. one folder name that doesn't work for you. In Windows Explorer, attempt to rename the folder (don't actually rename it) just copy the name and then paste it into Notepad. Save the file, specifying Unicode as the encoding (not big endian Unicode). Write a simple test script to use the file system object to read that saved list as Unicode. Use Msgbox to verify that the Unicode file is being read correctly. If it doesn't work, post your test script. If it works, add code to get a file system folder object for that folder and verify it gives you a correct list of the folder's contents. "Unicode" can be encoded many different ways. The file system object understands little endian 16-bit Unicode and 8-bit Ansi. -Paul Randall |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Scanning multiple folders for files possible? "Pegasus [MVP]" <news@xxxxxx> wrote in message news:%23KopdGK0JHA.5528@xxxxxx Quote: > > "alm80" <alm80@xxxxxx> wrote in message > news:074717AA-F9C6-41CF-93DD-2446BE43E7D7@xxxxxx Quote: >> >> >> "Pegasus [MVP]" wrote: >> >> Quote: >>> VB Script is a highly appropriate language for this type of thing. >>> >>> It is easy to get VB Script to scan multiple folders but you need to be >>> clear which of these options apply: >>> a) Scan every folder that you specify in your script. >>> b) Scan every subfolder of the specified folder, one level deep. >>> c) Recursively scan every subfolder of the nominated folder. >>> >>> You also need to be clearer what you mean with "if the contents of the >>> folder is modified, only the additional files would be scanned". Scanned >>> when the code is run next time? Or scanned during the current run? The >>> usual >>> process goes like this: >>> - Scan one folder >>> - Move on to the next folder. >>> - Scan it. >>> - Continue until you run out of folders. >>> The need to "mark" folders does not arise with this method - it simply >>> processes every folder it finds, without repeating itself. >>> >>> >> The task is to scan the folder and all the subfolders. The contents of >> the >> folders would not be modified during the scan, but can be different (some >> files added) at the next run. In most cases however the contents would >> not be >> modified ever, that means that once scanned and marked as scanned the >> folders would not need to be scanned anymore. Another problem is that >> many >> folders names use unicode non-latin characters. So far in my experiments, >> the >> script failed to recognize non-latin characters. > Try this code fragment: > Set oFSO = CreateObject("Scripting.FileSystemObject") > sFolder = "d:\Sat" > Set oParent = oFSO.GetFolder(sFolder) > For Each oFolder In oParent.SubFolders > WScript.Echo oFolder.Name > Next > > the GetFolder and SubFolders methods to enumerate folders. In each folder you can enumerate the Files collection. For each file you can create a textstream object to read the contents. The InStr function can check if a specified string is found. A basic example could be: =========== Option Explicit Dim strSearchPath, strSearchString, objFSO ' Specify path to search. strSearchPath = "c:\scripts" ' Specify string to search for. strSearchString = "NameTranslate" Set objFSO = CreateObject("Scripting.FileSystemObject") Call SearchFiles(strSearchPath, strSearchString) Sub SearchFiles(ByVal strPath, ByVal strSearch) ' Recursive Subroutine to search files for ' for a string. Dim objFolder, objFiles, strFile, objStream, objFile Dim strText, strFolder Const ForReading = 1 Set objFolder = objFSO.GetFolder(strPath) Set objFiles = objFolder.Files For Each strFile In objFiles Set objFile = objFSO.GetFile(strFile) If (objFile.Size > 0) Then Set objStream = objFSO.OpenTextFile(strFile, ForReading) strText = LCase(objStream.ReadAll) If (InStr(strText, LCase(strSearch)) > 0) Then Wscript.Echo strFile End If objStream.Close End If Next For Each strFolder In objFolder.SubFolders Call SearchFiles(strFolder, strSearch) Next End Sub ========= A more elaborate example is linked here: http://www.rlmueller.net/FindFiles.htm I can't think of a way to "mark" files as scanned, unless you maintain a database of all files or spit out a list of scanned files that you read the next time. Better might be to check the DateLastmodified property of the file object and only search files modified after a specified date. For example, you could replace this line: If (objFile.Size > 0) Then with this: If (objFile.Size > 0) And (objFile.DateLastModified > #1/1/2009#) Then So you only consider files modifed after a specified date. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Selecting multiple files/folders | Vista account administration | |||
| Cannot select multiple files in some folders. | Vista General | |||
| Selecting multiple files/folders | Vista General | |||
| Selecting multiple files/folders | Vista file management | |||
| Multiple folders and files for one user | Vista General | |||