Prev: Searching for Field Names
Next: Regular expression : f(" l'éléphant blEu-azUr ") = " L'Éléphant Bleu-Azur "
From: Copy Folders Copy on 21 Jan 2010 11:37 I have a script that searches a drive for a specific folder name and writes to a text file with the path. I would like to create a sub routine to then read the text and make a copy of that folder and contents to a USB Hard drive. (If possible with a progress bar to show me the status of the copy operation . ) Here is a copy of the code that I'm using. Thank you all in advance. -Jeremy Code: Set objRegEx = CreateObject("VBScript.RegExp") Set objFSO=CreateObject("Scripting.FileSystemObject") Set objFile=objFSO.CreateTextFile("C:\SearchLog.txt") 'Added to log the results objRegEx.Global = True objRegEx.IgnoreCase = True objRegex.Pattern = "^.*\b(Starwood Hotels)\b.*$" 'objRegEx.Pattern = "^bad_\d{8}" strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colFolders = objWMIService.ExecQuery("Select * From Win32_Directory") For Each objFolder in colFolders strFolder = objFolder.FileName Set colMatches = objRegEx.Execute(strFolder) If colMatches.Count > 0 Then objFile.WriteLine objFolder.Name 'Wscript.Echo objFolder.Name 'Replace with above to write to text End If Next
From: Al Dunbar on 21 Jan 2010 23:31 I find this a bit vague... "Copy Folders" <Copy Folders(a)discussions.microsoft.com> wrote in message news:E0561114-2538-4994-B9F3-EC74FF4FBB56(a)microsoft.com... > I have a script that searches a drive for a specific folder name and > writes > to a text file with the path. what does it write to a text file, the path? the path to what, the folder? or does it write to "a text file with a path"? > I would like to create a sub routine to then > read the text I assume you mean to read the text (content) of the file just written. Why bother? Your script wrote this file so it already has the content. > and make a copy of that folder and contents to a USB Hard > drive. why not have your script do that as soon as it finds the folder instead of first writing something to a file and then reading it backÉ /Al .. (If possible with a progress bar to show me the status of the copy > operation . ) Here is a copy of the code that I'm using. > > Thank you all in advance. -Jeremy > > Code: > > Set objRegEx = CreateObject("VBScript.RegExp") > Set objFSO=CreateObject("Scripting.FileSystemObject") > Set objFile=objFSO.CreateTextFile("C:\SearchLog.txt") 'Added to log the > results > > objRegEx.Global = True > objRegEx.IgnoreCase = True > objRegex.Pattern = "^.*\b(Starwood Hotels)\b.*$" > 'objRegEx.Pattern = "^bad_\d{8}" > > strComputer = "." > > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") > > Set colFolders = objWMIService.ExecQuery("Select * From Win32_Directory") > > For Each objFolder in colFolders > strFolder = objFolder.FileName > Set colMatches = objRegEx.Execute(strFolder) > > If colMatches.Count > 0 Then > objFile.WriteLine objFolder.Name > 'Wscript.Echo objFolder.Name 'Replace with above to write to > text > End If > Next >
From: Paul Randall on 22 Jan 2010 09:30 I don't have my references with me, and groups.google.com is not finding what I wanted to show you. You can use the shell object to access through vbscript, much of the functionality that you can access through folder windows and the mouse, including copying folders from one path to another with progress bar. Go to msdn.microsoft.com and search for words like vbscript and shell and copyhere and namespace. Besides the reference material, you may also find complete sample code from 'the scripting guys'. Here are some links: http://msdn.microsoft.com/en-us/library/bb776890(VS.85).aspx http://msdn.microsoft.com/en-us/library/bb787866(VS.85).aspx -Paul Randall "Copy Folders" <Copy Folders(a)discussions.microsoft.com> wrote in message news:E0561114-2538-4994-B9F3-EC74FF4FBB56(a)microsoft.com... >I have a script that searches a drive for a specific folder name and writes > to a text file with the path. I would like to create a sub routine to then > read the text and make a copy of that folder and contents to a USB Hard > drive. (If possible with a progress bar to show me the status of the copy > operation . ) Here is a copy of the code that I'm using. > > Thank you all in advance. -Jeremy > > Code: > > Set objRegEx = CreateObject("VBScript.RegExp") > Set objFSO=CreateObject("Scripting.FileSystemObject") > Set objFile=objFSO.CreateTextFile("C:\SearchLog.txt") 'Added to log the > results > > objRegEx.Global = True > objRegEx.IgnoreCase = True > objRegex.Pattern = "^.*\b(Starwood Hotels)\b.*$" > 'objRegEx.Pattern = "^bad_\d{8}" > > strComputer = "." > > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") > > Set colFolders = objWMIService.ExecQuery("Select * From Win32_Directory") > > For Each objFolder in colFolders > strFolder = objFolder.FileName > Set colMatches = objRegEx.Execute(strFolder) > > If colMatches.Count > 0 Then > objFile.WriteLine objFolder.Name > 'Wscript.Echo objFolder.Name 'Replace with above to write to > text > End If > Next >
From: Copy Folders on 22 Jan 2010 11:01 Hi Al , As you can probably figure out , I'm not a programmer. I can understand a little of vb , I found this script on the net and tweaked it . The text file has the full path of the folders. Here is what the text file contains: g:\jobs 2006\jobs 06-0600-0649\06-0624 starwood hotels & re g:\jobs 2006\jobs 06-1700-1749\06-1704 starwood hotels & re g:\jobs 2006\jobs 06-1700-1749\06-1705 starwood hotels & re The list is pretty big. After its written to the text file , I would need a sub routine to read line by line and copy only these folders and it's content to a USB drive. If you have any examples , that would be awesome. "Al Dunbar" wrote: > I find this a bit vague... > > "Copy Folders" <Copy Folders(a)discussions.microsoft.com> wrote in message > news:E0561114-2538-4994-B9F3-EC74FF4FBB56(a)microsoft.com... > > I have a script that searches a drive for a specific folder name and > > writes > > to a text file with the path. > > what does it write to a text file, the path? the path to what, the folder? > or does it write to "a text file with a path"? > > > I would like to create a sub routine to then > > read the text > > I assume you mean to read the text (content) of the file just written. Why > bother? Your script wrote this file so it already has the content. > > > and make a copy of that folder and contents to a USB Hard > > drive. > > why not have your script do that as soon as it finds the folder instead of > first writing something to a file and then reading it backÉ > > /Al > > . (If possible with a progress bar to show me the status of the copy > > operation . ) Here is a copy of the code that I'm using. > > > > Thank you all in advance. -Jeremy > > > > Code: > > > > Set objRegEx = CreateObject("VBScript.RegExp") > > Set objFSO=CreateObject("Scripting.FileSystemObject") > > Set objFile=objFSO.CreateTextFile("C:\SearchLog.txt") 'Added to log the > > results > > > > objRegEx.Global = True > > objRegEx.IgnoreCase = True > > objRegex.Pattern = "^.*\b(Starwood Hotels)\b.*$" > > 'objRegEx.Pattern = "^bad_\d{8}" > > > > strComputer = "." > > > > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") > > > > Set colFolders = objWMIService.ExecQuery("Select * From Win32_Directory") > > > > For Each objFolder in colFolders > > strFolder = objFolder.FileName > > Set colMatches = objRegEx.Execute(strFolder) > > > > If colMatches.Count > 0 Then > > objFile.WriteLine objFolder.Name > > 'Wscript.Echo objFolder.Name 'Replace with above to write to > > text > > End If > > Next > >
From: Al Dunbar on 1 Feb 2010 00:43 "Copy Folders" <CopyFolders(a)discussions.microsoft.com> wrote in message news:C6C69867-37D8-43B4-958C-D3552D7A582E(a)microsoft.com... > Hi Al , > > As you can probably figure out , I'm not a programmer. I can understand a > little of vb , I found this script on the net and tweaked it . > > The text file has the full path of the folders. Here is what the text file > contains: > g:\jobs 2006\jobs 06-0600-0649\06-0624 starwood hotels & re > g:\jobs 2006\jobs 06-1700-1749\06-1704 starwood hotels & re > g:\jobs 2006\jobs 06-1700-1749\06-1705 starwood hotels & re > > The list is pretty big. After its written to the text file , I would need > a > sub routine to read line by line and copy only these folders and it's > content > to a USB drive. To be perfectly honest, some of us would find it much easier to do this in batch rather than vbscript. The only issue with that is that batch code suffers when data contains "poison characters", of which "&" is one... ;-( Other than that quirk, a batch file to do what you ask could look something like this: @echo off for /f "delims=" %%F in (textfile.txt) do ( xcopy "%%~F" E:\ ) It is not clear from your clarification above whether you expect these folders to be copied to the root folder of the USB (which would be a problem if two of the folders had the same name), or if you want the same folder structure as the original. /Al > If you have any examples , that would be awesome. > > "Al Dunbar" wrote: > >> I find this a bit vague... >> >> "Copy Folders" <Copy Folders(a)discussions.microsoft.com> wrote in message >> news:E0561114-2538-4994-B9F3-EC74FF4FBB56(a)microsoft.com... >> > I have a script that searches a drive for a specific folder name and >> > writes >> > to a text file with the path. >> >> what does it write to a text file, the path? the path to what, the >> folder? >> or does it write to "a text file with a path"? >> >> > I would like to create a sub routine to then >> > read the text >> >> I assume you mean to read the text (content) of the file just written. >> Why >> bother? Your script wrote this file so it already has the content. >> >> > and make a copy of that folder and contents to a USB Hard >> > drive. >> >> why not have your script do that as soon as it finds the folder instead >> of >> first writing something to a file and then reading it backÉ >> >> /Al >> >> . (If possible with a progress bar to show me the status of the copy >> > operation . ) Here is a copy of the code that I'm using. >> > >> > Thank you all in advance. -Jeremy >> > >> > Code: >> > >> > Set objRegEx = CreateObject("VBScript.RegExp") >> > Set objFSO=CreateObject("Scripting.FileSystemObject") >> > Set objFile=objFSO.CreateTextFile("C:\SearchLog.txt") 'Added to log the >> > results >> > >> > objRegEx.Global = True >> > objRegEx.IgnoreCase = True >> > objRegex.Pattern = "^.*\b(Starwood Hotels)\b.*$" >> > 'objRegEx.Pattern = "^bad_\d{8}" >> > >> > strComputer = "." >> > >> > Set objWMIService = GetObject("winmgmts:\\" & strComputer & >> > "\root\cimv2") >> > >> > Set colFolders = objWMIService.ExecQuery("Select * From >> > Win32_Directory") >> > >> > For Each objFolder in colFolders >> > strFolder = objFolder.FileName >> > Set colMatches = objRegEx.Execute(strFolder) >> > >> > If colMatches.Count > 0 Then >> > objFile.WriteLine objFolder.Name >> > 'Wscript.Echo objFolder.Name 'Replace with above to write >> > to >> > text >> > End If >> > Next >> >
|
Next
|
Last
Pages: 1 2 Prev: Searching for Field Names Next: Regular expression : f(" l'éléphant blEu-azUr ") = " L'Éléphant Bleu-Azur " |