Hey All....

Can anyone help me with the easiest way would be to make the script
below to traverse subfolders and perform the file copy from the txt
file list?

I want to remove the hard coded "source", and put the root folder H:\
and traverse it looking for the files.

Thanks in advance!!!!

set fso = createobject("scripting.filesystemobject")
Set objShell = CreateObject("wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objErrLog = objFSO.OpenTextFile("H:
\August07_Missing_Restore_Log.log", 8, True)

On Error Resume Next

sFile = "H:\August07.txt"
dest = "H:\Restore\August07\"

Set txtStream = fso.OpenTextFile(sfile) ' Open text file.
Do While Not (txtStream.atEndOfStream) ' Read each line of the file
Filename = txtStream.ReadLine
source = "\\server\archive\" & Filename
'wscript.echo source

If objFSO.FileExists(source) Then
intRunError = ObjShell.Run("%COMSPEC% /c Echo Y| fileacl " _
& source & " /o administrators", 2, True)
If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for user " _
& strUser & " to file " & source
End If
Else
objErrLog.WriteLine source & " - Error: File Does Not Exist! - " &
Now
End If

fso.copyfile source, dest, true
Loop

wscript.echo "DONE!!!!"

Re: vbscript to traverse subfolders by Pegasus

Pegasus
Wed Mar 12 14:34:04 CDT 2008


"tiv" <jmattivi@gmail.com> wrote in message
news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
> Hey All....
>
> Can anyone help me with the easiest way would be to make the script
> below to traverse subfolders and perform the file copy from the txt
> file list?
>
> I want to remove the hard coded "source", and put the root folder H:\
> and traverse it looking for the files.
>
> Thanks in advance!!!!
>
> set fso = createobject("scripting.filesystemobject")
> Set objShell = CreateObject("wscript.Shell")
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objErrLog = objFSO.OpenTextFile("H:
> \August07_Missing_Restore_Log.log", 8, True)
>
> On Error Resume Next
>
> sFile = "H:\August07.txt"
> dest = "H:\Restore\August07\"
>
> Set txtStream = fso.OpenTextFile(sfile) ' Open text file.
> Do While Not (txtStream.atEndOfStream) ' Read each line of the file
> Filename = txtStream.ReadLine
> source = "\\server\archive\" & Filename
> 'wscript.echo source
>
> If objFSO.FileExists(source) Then
> intRunError = ObjShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> & source & " /o administrators", 2, True)
> If intRunError <> 0 Then
> Wscript.Echo "Error assigning permissions for user " _
> & strUser & " to file " & source
> End If
> Else
> objErrLog.WriteLine source & " - Error: File Does Not Exist! - " &
> Now
> End If
>
> fso.copyfile source, dest, true
> Loop
>
> wscript.echo "DONE!!!!"
>

Your intention is a little unclear. Do you plan to copy the
same file to each and every branch in a directory tree?

Also: If you are able to modify the access permissions of
a file then you are also able to overwrite it. Why would
therefore bother to change the permissions?



Re: vbscript to traverse subfolders by tiv

tiv
Wed Mar 12 15:04:13 CDT 2008

On Mar 12, 3:34 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "tiv" <jmatt...@gmail.com> wrote in message
>
> news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
>
>
>
> > Hey All....
>
> > Can anyone help me with the easiest way would be to make the script
> > below to traverse subfolders and perform the file copy from the txt
> > file list?
>
> > I want to remove the hard coded "source", and put the root folder H:\
> > and traverse it looking for the files.
>
> > Thanks in advance!!!!
>
> > set fso = createobject("scripting.filesystemobject")
> > Set objShell = CreateObject("wscript.Shell")
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set objErrLog = objFSO.OpenTextFile("H:
> > \August07_Missing_Restore_Log.log", 8, True)
>
> > On Error Resume Next
>
> > sFile = "H:\August07.txt"
> > dest = "H:\Restore\August07\"
>
> > Set txtStream = fso.OpenTextFile(sfile) ' Open text file.
> > Do While Not (txtStream.atEndOfStream) ' Read each line of the file
> > Filename = txtStream.ReadLine
> > source = "\\server\archive\" & Filename
> > 'wscript.echo source
>
> > If objFSO.FileExists(source) Then
> > intRunError = ObjShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> > & source & " /o administrators", 2, True)
> > If intRunError <> 0 Then
> > Wscript.Echo "Error assigning permissions for user " _
> > & strUser & " to file " & source
> > End If
> > Else
> > objErrLog.WriteLine source & " - Error: File Does Not Exist! - " &
> > Now
> > End If
>
> > fso.copyfile source, dest, true
> > Loop
>
> > wscript.echo "DONE!!!!"
>
> Your intention is a little unclear. Do you plan to copy the
> same file to each and every branch in a directory tree?
>
> Also: If you are able to modify the access permissions of
> a file then you are also able to overwrite it. Why would
> therefore bother to change the permissions?

I am doing a search for files contained in August07.txt -> "sfile". I
want to search through the root and subfolders for these files and
once they are found,copy them to the target directory. The owner on
some files in the one directory seems to be corrupt, so i want to set
the owner. Nothing is being overwritten, just copied to a repository.
Tested and this does work on a hard coded folder to search/copy files
from.
Thanks and please let me know if you have any/all questions!!

Re: vbscript to traverse subfolders by Pegasus

Pegasus
Wed Mar 12 17:22:32 CDT 2008


"tiv" <jmattivi@gmail.com> wrote in message
news:822d8659-5955-42f5-beb4-6980982ac723@e6g2000prf.googlegroups.com...
> On Mar 12, 3:34 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>> "tiv" <jmatt...@gmail.com> wrote in message
>>
>> news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
>>
>>
>>
>> > Hey All....
>>
>> > Can anyone help me with the easiest way would be to make the script
>> > below to traverse subfolders and perform the file copy from the txt
>> > file list?
>>
>> > I want to remove the hard coded "source", and put the root folder H:\
>> > and traverse it looking for the files.
>>
>> > Thanks in advance!!!!
>>
>> > set fso = createobject("scripting.filesystemobject")
>> > Set objShell = CreateObject("wscript.Shell")
>> > Set objFSO = CreateObject("Scripting.FileSystemObject")
>> > Set objErrLog = objFSO.OpenTextFile("H:
>> > \August07_Missing_Restore_Log.log", 8, True)
>>
>> > On Error Resume Next
>>
>> > sFile = "H:\August07.txt"
>> > dest = "H:\Restore\August07\"
>>
>> > Set txtStream = fso.OpenTextFile(sfile) ' Open text file.
>> > Do While Not (txtStream.atEndOfStream) ' Read each line of the file
>> > Filename = txtStream.ReadLine
>> > source = "\\server\archive\" & Filename
>> > 'wscript.echo source
>>
>> > If objFSO.FileExists(source) Then
>> > intRunError = ObjShell.Run("%COMSPEC% /c Echo Y| fileacl " _
>> > & source & " /o administrators", 2, True)
>> > If intRunError <> 0 Then
>> > Wscript.Echo "Error assigning permissions for user " _
>> > & strUser & " to file " & source
>> > End If
>> > Else
>> > objErrLog.WriteLine source & " - Error: File Does Not Exist! - " &
>> > Now
>> > End If
>>
>> > fso.copyfile source, dest, true
>> > Loop
>>
>> > wscript.echo "DONE!!!!"
>>
>> Your intention is a little unclear. Do you plan to copy the
>> same file to each and every branch in a directory tree?
>>
>> Also: If you are able to modify the access permissions of
>> a file then you are also able to overwrite it. Why would
>> therefore bother to change the permissions?
>
> I am doing a search for files contained in August07.txt -> "sfile". I
> want to search through the root and subfolders for these files and
> once they are found,copy them to the target directory. The owner on
> some files in the one directory seems to be corrupt, so i want to set
> the owner. Nothing is being overwritten, just copied to a repository.
> Tested and this does work on a hard coded folder to search/copy files
> from.
> Thanks and please let me know if you have any/all questions!!

I think there may be a flaw in your design. If the file you're
looking for exists in several branches of the directory tree
then you're going to overwrite it if you copy it to the same
target folder.

Anyway, here is a script the should do what you want. It
uses a recursive subroutine to access all folders in the
directory tree. Note that I did not test the permission stuff.

Set objShell = CreateObject("wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Const sLog = "D:\temp\Log.txt"
Const strUser = "Pegasus"
Const sFile = "d:\Temp\Files.txt"
Const source = "\\Pegasus\Data"
Const dest = "D:\August"
Set objErrLog = objFSO.OpenTextFile(sLog, 8, True)

On Error Resume Next
if not objfso.FolderExists(dest) then objFSO.CreateFolder(dest)
If Err > 0 Then
WScript.Echo "Cannot create the folder """ & dest & """"
WScript.Echo Err.Description
WScript.Quit
End If
On Error Goto 0

If Not objFSO.FileExists(sFile) Then
WScript.Echo "Cannot open the file """ & sFile & """"
WScript.Quit
End If

Set txtStream = objFSO.OpenTextFile(sfile, 1) ' Open text file.
Do While Not (txtStream.atEndOfStream) ' Read each line of the file
Filename = txtStream.ReadLine
FindFile source, Filename
Loop

'===================================

Sub FindFile(S, F)
FN = S & "\" & F
WScript.Echo "Searching " & S & " for " & F
If objFSO.FileExists(FN) Then
' intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
' & FN & " /o administrators", 2, True)
' If intRunError <> 0 Then
' WScript.Echo "Error assigning permissions for user " _
' & strUser & " to file " & FN
' End If
objFSO.copyfile FN, dest & "\" & F, True
Else
objErrLog.WriteLine FN _
& " - Error: File Does Not Exist! - " & Now
End If

Set objFolder = objFSO.GetFolder(S)
Set colFolders = objFolder.SubFolders
For Each sFolder In colFolders
FindFile sFolder, Filename
Next
End Sub



Re: vbscript to traverse subfolders by tiv

tiv
Thu Mar 13 08:40:41 CDT 2008

On Mar 12, 6:22 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "tiv" <jmatt...@gmail.com> wrote in message
>
> news:822d8659-5955-42f5-beb4-6980982ac723@e6g2000prf.googlegroups.com...
>
>
>
> > On Mar 12, 3:34 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> >> "tiv" <jmatt...@gmail.com> wrote in message
>
> >>news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
>
> >> > Hey All....
>
> >> > Can anyone help me with the easiest way would be to make the script
> >> > below to traverse subfolders and perform the file copy from the txt
> >> > file list?
>
> >> > I want to remove the hard coded "source", and put the root folder H:\
> >> > and traverse it looking for the files.
>
> >> > Thanks in advance!!!!
>
> >> > set fso = createobject("scripting.filesystemobject")
> >> > Set objShell = CreateObject("wscript.Shell")
> >> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> >> > Set objErrLog = objFSO.OpenTextFile("H:
> >> > \August07_Missing_Restore_Log.log", 8, True)
>
> >> > On Error Resume Next
>
> >> > sFile = "H:\August07.txt"
> >> > dest = "H:\Restore\August07\"
>
> >> > Set txtStream = fso.OpenTextFile(sfile) ' Open text file.
> >> > Do While Not (txtStream.atEndOfStream) ' Read each line of the file
> >> > Filename = txtStream.ReadLine
> >> > source = "\\server\archive\" & Filename
> >> > 'wscript.echo source
>
> >> > If objFSO.FileExists(source) Then
> >> > intRunError = ObjShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> >> > & source & " /o administrators", 2, True)
> >> > If intRunError <> 0 Then
> >> > Wscript.Echo "Error assigning permissions for user " _
> >> > & strUser & " to file " & source
> >> > End If
> >> > Else
> >> > objErrLog.WriteLine source & " - Error: File Does Not Exist! - " &
> >> > Now
> >> > End If
>
> >> > fso.copyfile source, dest, true
> >> > Loop
>
> >> > wscript.echo "DONE!!!!"
>
> >> Your intention is a little unclear. Do you plan to copy the
> >> same file to each and every branch in a directory tree?
>
> >> Also: If you are able to modify the access permissions of
> >> a file then you are also able to overwrite it. Why would
> >> therefore bother to change the permissions?
>
> > I am doing a search for files contained in August07.txt -> "sfile". I
> > want to search through the root and subfolders for these files and
> > once they are found,copy them to the target directory. The owner on
> > some files in the one directory seems to be corrupt, so i want to set
> > the owner. Nothing is being overwritten, just copied to a repository.
> > Tested and this does work on a hard coded folder to search/copy files
> > from.
> > Thanks and please let me know if you have any/all questions!!
>
> I think there may be a flaw in your design. If the file you're
> looking for exists in several branches of the directory tree
> then you're going to overwrite it if you copy it to the same
> target folder.
>
> Anyway, here is a script the should do what you want. It
> uses a recursive subroutine to access all folders in the
> directory tree. Note that I did not test the permission stuff.
>
> Set objShell = CreateObject("wscript.Shell")
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> Const sLog = "D:\temp\Log.txt"
> Const strUser = "Pegasus"
> Const sFile = "d:\Temp\Files.txt"
> Const source = "\\Pegasus\Data"
> Const dest = "D:\August"
> Set objErrLog = objFSO.OpenTextFile(sLog, 8, True)
>
> On Error Resume Next
> if not objfso.FolderExists(dest) then objFSO.CreateFolder(dest)
> If Err > 0 Then
> WScript.Echo "Cannot create the folder """ & dest & """"
> WScript.Echo Err.Description
> WScript.Quit
> End If
> On Error Goto 0
>
> If Not objFSO.FileExists(sFile) Then
> WScript.Echo "Cannot open the file """ & sFile & """"
> WScript.Quit
> End If
>
> Set txtStream = objFSO.OpenTextFile(sfile, 1) ' Open text file.
> Do While Not (txtStream.atEndOfStream) ' Read each line of the file
> Filename = txtStream.ReadLine
> FindFile source, Filename
> Loop
>
> '===================================
>
> Sub FindFile(S, F)
> FN = S & "\" & F
> WScript.Echo "Searching " & S & " for " & F
> If objFSO.FileExists(FN) Then
> ' intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> ' & FN & " /o administrators", 2, True)
> ' If intRunError <> 0 Then
> ' WScript.Echo "Error assigning permissions for user " _
> ' & strUser & " to file " & FN
> ' End If
> objFSO.copyfile FN, dest & "\" & F, True
> Else
> objErrLog.WriteLine FN _
> & " - Error: File Does Not Exist! - " & Now
> End If
>
> Set objFolder = objFSO.GetFolder(S)
> Set colFolders = objFolder.SubFolders
> For Each sFolder In colFolders
> FindFile sFolder, Filename
> Next
> End Sub

YES!!! That does exactly what i want for looking through the
subfolders. Thing is, there is only going to be one file per unique
name in the entire folder tree. So is there any way that if it finds
and copies the file to the destination = true, that it moves on to the
next file in the lookup txt file? I've tested and after it finds and
copies the file, it continues to look through the subsequent folders
for the same file. I'm not sure, but would it need an IF statement
and return in the event if the COPY statement is true? Actually after
reading this it still sounds unclear....I want it to copy File1 from
the lookup txt file - "sfile", return to the root of the folders
"source" and move to the next file "File2" in the lookup txt - "sfile"
and so on and so on. Being that i need to find about 1500 files in
"sfile"....

THANK YOU so much again! This is invaluable!! (And the permissions
to work great as well!!) :)

Re: vbscript to traverse subfolders by Tom

Tom
Thu Mar 13 09:26:24 CDT 2008

On Mar 13, 9:40 am, tiv <jmatt...@gmail.com> wrote:
> On Mar 12, 6:22 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>
>
>
> > "tiv" <jmatt...@gmail.com> wrote in message
>
> >news:822d8659-5955-42f5-beb4-6980982ac723@e6g2000prf.googlegroups.com...
>
> > > On Mar 12, 3:34 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> > >> "tiv" <jmatt...@gmail.com> wrote in message
>
> > >>news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
>
> > >> > Hey All....
>
{snip}
> YES!!! That does exactly what i want for looking through the
> subfolders. Thing is, there is only going to be one file per unique
> name in the entire folder tree. So is there any way that if it finds
> and copies the file to the destination = true, that it moves on to the
> next file in the lookup txt file? I've tested and after it finds and
> copies the file, it continues to look through the subsequent folders
> for the same file. I'm not sure, but would it need an IF statement
> and return in the event if the COPY statement is true? Actually after
> reading this it still sounds unclear....I want it to copy File1 from
> the lookup txt file - "sfile", return to the root of the folders
> "source" and move to the next file "File2" in the lookup txt - "sfile"
> and so on and so on. Being that i need to find about 1500 files in
> "sfile"....
>
> THANK YOU so much again! This is invaluable!! (And the permissions
> to work great as well!!) :)

I believe the following modifications would do the job (but I didn't
take the time to test it) ...

Function FindFile(S, F) ' now a function - returns True if found
FindFile = False
FN = S & "\" & F
WScript.Echo "Searching " & S & " for " & F
If objFSO.FileExists(FN) Then
' intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
' & FN & " /o administrators", 2, True)
' If intRunError <> 0 Then
' WScript.Echo "Error assigning permissions for user " _
' & strUser & " to file " & FN
' End If
objFSO.copyfile FN, dest & "\" & F, True
FindFile = True ' return True when found
exit sub ' stop searching
Else
' --------------------------------------------------------
' I don't think this is the right place for this
' I believe it puts a log entry for every folder searched
' that fails to have the file in it.
'
objErrLog.WriteLine FN _
& " - Error: File Does Not Exist! - " & Now
End If
' --------------------------------------------------------

Set objFolder = objFSO.GetFolder(S)
Set colFolders = objFolder.SubFolders
For Each sFolder In colFolders
FindFile sFolder, Filename
if FindFile then exit next ' ensure exit from recursion
Next
End Sub

As I said, this is not tested (just don't have the time). Recursive
routines can be tricky and time consuming to test. Hopefully, I got
it right.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: vbscript to traverse subfolders by tiv

tiv
Thu Mar 13 11:58:18 CDT 2008

On Mar 13, 10:26 am, Tom Lavedas <tglba...@cox.net> wrote:
> On Mar 13, 9:40 am, tiv <jmatt...@gmail.com> wrote:
>
>
>
> > On Mar 12, 6:22 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>
> > > "tiv" <jmatt...@gmail.com> wrote in message
>
> > >news:822d8659-5955-42f5-beb4-6980982ac723@e6g2000prf.googlegroups.com...
>
> > > > On Mar 12, 3:34 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> > > >> "tiv" <jmatt...@gmail.com> wrote in message
>
> > > >>news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
>
> > > >> > Hey All....
>
> {snip}
> > YES!!! That does exactly what i want for looking through the
> > subfolders. Thing is, there is only going to be one file per unique
> > name in the entire folder tree. So is there any way that if it finds
> > and copies the file to the destination = true, that it moves on to the
> > next file in the lookup txt file? I've tested and after it finds and
> > copies the file, it continues to look through the subsequent folders
> > for the same file. I'm not sure, but would it need an IF statement
> > and return in the event if the COPY statement is true? Actually after
> > reading this it still sounds unclear....I want it to copy File1 from
> > the lookup txt file - "sfile", return to the root of the folders
> > "source" and move to the next file "File2" in the lookup txt - "sfile"
> > and so on and so on. Being that i need to find about 1500 files in
> > "sfile"....
>
> > THANK YOU so much again! This is invaluable!! (And the permissions
> > to work great as well!!) :)
>
> I believe the following modifications would do the job (but I didn't
> take the time to test it) ...
>
> Function FindFile(S, F) ' now a function - returns True if found
> FindFile = False
> FN = S & "\" & F
> WScript.Echo "Searching " & S & " for " & F
> If objFSO.FileExists(FN) Then
> ' intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> ' & FN & " /o administrators", 2, True)
> ' If intRunError <> 0 Then
> ' WScript.Echo "Error assigning permissions for user " _
> ' & strUser & " to file " & FN
> ' End If
> objFSO.copyfile FN, dest & "\" & F, True
> FindFile = True ' return True when found
> exit sub ' stop searching
> Else
> ' --------------------------------------------------------
> ' I don't think this is the right place for this
> ' I believe it puts a log entry for every folder searched
> ' that fails to have the file in it.
> '
> objErrLog.WriteLine FN _
> & " - Error: File Does Not Exist! - " & Now
> End If
> ' --------------------------------------------------------
>
> Set objFolder = objFSO.GetFolder(S)
> Set colFolders = objFolder.SubFolders
> For Each sFolder In colFolders
> FindFile sFolder, Filename
> if FindFile then exit next ' ensure exit from recursion
> Next
> End Sub
>
> As I said, this is not tested (just don't have the time). Recursive
> routines can be tricky and time consuming to test. Hopefully, I got
> it right.
>
> Tom Lavedas
> ===========http://members.cox.net/tglbatch/wsh/

This is what i have now....it works, but continues to traverse the
subfolders after finding/copying the file.

Function FindFile(S, F) ' now a function - returns True if found
FindFile = False
FN = S & "\" & F
WScript.Echo "Searching " & S & " for " & F
If objFSO.FileExists(FN) Then
intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
& FN & " /o administrators", 2, True)
If intRunError <> 0 Then
WScript.Echo "Error assigning permissions for user " _
& strUser & " to file " & FN
End If
objFSO.copyfile FN, dest & "\" & F, True
if FindFile = True then
exit Function ' ensure exit from recursion

end if

Else

Set objFolder = objFSO.GetFolder(S)
Set colFolders = objFolder.SubFolders
For Each sFolder In colFolders
FindFile sFolder, Filename
if FindFile = True then exit Function ' ensure exit from recursion
Next
end if
End Function

Re: vbscript to traverse subfolders by Paul

Paul
Thu Mar 13 12:46:29 CDT 2008


"tiv" <jmattivi@gmail.com> wrote in message
news:b238f7e0-f6e4-48bc-8ab9-43fe0ef6ca6c@e25g2000prg.googlegroups.com...
> On Mar 13, 10:26 am, Tom Lavedas <tglba...@cox.net> wrote:
>> On Mar 13, 9:40 am, tiv <jmatt...@gmail.com> wrote:
>>
>>
>>
>> > On Mar 12, 6:22 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>>
>> > > "tiv" <jmatt...@gmail.com> wrote in message
>>
>> > >news:822d8659-5955-42f5-beb4-6980982ac723@e6g2000prf.googlegroups.com...
>>
>> > > > On Mar 12, 3:34 pm, "Pegasus \(MVP\)" <I....@fly.com.oz>
>> > > > wrote:
>> > > >> "tiv" <jmatt...@gmail.com> wrote in message
>>
>> > > >>news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
>>
>> > > >> > Hey All....
>>
>> {snip}
>> > YES!!! That does exactly what i want for looking through the
>> > subfolders. Thing is, there is only going to be one file per
>> > unique
>> > name in the entire folder tree. So is there any way that if it
>> > finds
>> > and copies the file to the destination = true, that it moves on
>> > to the
>> > next file in the lookup txt file? I've tested and after it finds
>> > and
>> > copies the file, it continues to look through the subsequent
>> > folders
>> > for the same file. I'm not sure, but would it need an IF
>> > statement
>> > and return in the event if the COPY statement is true? Actually
>> > after
>> > reading this it still sounds unclear....I want it to copy File1
>> > from
>> > the lookup txt file - "sfile", return to the root of the folders
>> > "source" and move to the next file "File2" in the lookup txt -
>> > "sfile"
>> > and so on and so on. Being that i need to find about 1500 files
>> > in
>> > "sfile"....
>>
>> > THANK YOU so much again! This is invaluable!! (And the
>> > permissions
>> > to work great as well!!) :)
>>
>> I believe the following modifications would do the job (but I
>> didn't
>> take the time to test it) ...
>>
>> Function FindFile(S, F) ' now a function - returns True if found
>> FindFile = False
>> FN = S & "\" & F
>> WScript.Echo "Searching " & S & " for " & F
>> If objFSO.FileExists(FN) Then
>> ' intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
>> ' & FN & " /o administrators", 2, True)
>> ' If intRunError <> 0 Then
>> ' WScript.Echo "Error assigning permissions for user " _
>> ' & strUser & " to file " & FN
>> ' End If
>> objFSO.copyfile FN, dest & "\" & F, True
>> FindFile = True ' return True when found
>> exit sub ' stop searching
>> Else
>> ' --------------------------------------------------------
>> ' I don't think this is the right place for this
>> ' I believe it puts a log entry for every folder searched
>> ' that fails to have the file in it.
>> '
>> objErrLog.WriteLine FN _
>> & " - Error: File Does Not Exist! - " & Now
>> End If
>> ' --------------------------------------------------------
>>
>> Set objFolder = objFSO.GetFolder(S)
>> Set colFolders = objFolder.SubFolders
>> For Each sFolder In colFolders
>> FindFile sFolder, Filename
>> if FindFile then exit next ' ensure exit from recursion
>> Next
>> End Sub
>>
>> As I said, this is not tested (just don't have the time).
>> Recursive
>> routines can be tricky and time consuming to test. Hopefully, I
>> got
>> it right.
>>
>> Tom Lavedas
>> ===========http://members.cox.net/tglbatch/wsh/
>
> This is what i have now....it works, but continues to traverse the
> subfolders after finding/copying the file.
>
> Function FindFile(S, F) ' now a function - returns True if found
> FindFile = False
> FN = S & "\" & F
> WScript.Echo "Searching " & S & " for " & F

Assuming that the following statement checks for the file's existence

> If objFSO.FileExists(FN) Then
> intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> & FN & " /o administrators", 2, True)
> If intRunError <> 0 Then
> WScript.Echo "Error assigning permissions for user " _
> & strUser & " to file " & FN
> End If
> objFSO.copyfile FN, dest & "\" & F, True

Change the following statement

> if FindFile = True then

to
FindFile = True

> exit Function ' ensure exit from recursion
>
> end if
>
> Else
>
> Set objFolder = objFSO.GetFolder(S)
> Set colFolders = objFolder.SubFolders
> For Each sFolder In colFolders
> FindFile sFolder, Filename
> if FindFile = True then exit Function ' ensure exit from recursion
> Next
> end if
> End Function



Re: vbscript to traverse subfolders by tiv

tiv
Thu Mar 13 13:56:01 CDT 2008

On Mar 13, 1:46 pm, "Paul Randall" <paulr...@cableone.net> wrote:
> "tiv" <jmatt...@gmail.com> wrote in message
>
> news:b238f7e0-f6e4-48bc-8ab9-43fe0ef6ca6c@e25g2000prg.googlegroups.com...
>
>
>
> > On Mar 13, 10:26 am, Tom Lavedas <tglba...@cox.net> wrote:
> >> On Mar 13, 9:40 am, tiv <jmatt...@gmail.com> wrote:
>
> >> > On Mar 12, 6:22 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>
> >> > > "tiv" <jmatt...@gmail.com> wrote in message
>
> >> > >news:822d8659-5955-42f5-beb4-6980982ac723@e6g2000prf.googlegroups.com...
>
> >> > > > On Mar 12, 3:34 pm, "Pegasus \(MVP\)" <I....@fly.com.oz>
> >> > > > wrote:
> >> > > >> "tiv" <jmatt...@gmail.com> wrote in message
>
> >> > > >>news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
>
> >> > > >> > Hey All....
>
> >> {snip}
> >> > YES!!! That does exactly what i want for looking through the
> >> > subfolders. Thing is, there is only going to be one file per
> >> > unique
> >> > name in the entire folder tree. So is there any way that if it
> >> > finds
> >> > and copies the file to the destination = true, that it moves on
> >> > to the
> >> > next file in the lookup txt file? I've tested and after it finds
> >> > and
> >> > copies the file, it continues to look through the subsequent
> >> > folders
> >> > for the same file. I'm not sure, but would it need an IF
> >> > statement
> >> > and return in the event if the COPY statement is true? Actually
> >> > after
> >> > reading this it still sounds unclear....I want it to copy File1
> >> > from
> >> > the lookup txt file - "sfile", return to the root of the folders
> >> > "source" and move to the next file "File2" in the lookup txt -
> >> > "sfile"
> >> > and so on and so on. Being that i need to find about 1500 files
> >> > in
> >> > "sfile"....
>
> >> > THANK YOU so much again! This is invaluable!! (And the
> >> > permissions
> >> > to work great as well!!) :)
>
> >> I believe the following modifications would do the job (but I
> >> didn't
> >> take the time to test it) ...
>
> >> Function FindFile(S, F) ' now a function - returns True if found
> >> FindFile = False
> >> FN = S & "\" & F
> >> WScript.Echo "Searching " & S & " for " & F
> >> If objFSO.FileExists(FN) Then
> >> ' intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> >> ' & FN & " /o administrators", 2, True)
> >> ' If intRunError <> 0 Then
> >> ' WScript.Echo "Error assigning permissions for user " _
> >> ' & strUser & " to file " & FN
> >> ' End If
> >> objFSO.copyfile FN, dest & "\" & F, True
> >> FindFile = True ' return True when found
> >> exit sub ' stop searching
> >> Else
> >> ' --------------------------------------------------------
> >> ' I don't think this is the right place for this
> >> ' I believe it puts a log entry for every folder searched
> >> ' that fails to have the file in it.
> >> '
> >> objErrLog.WriteLine FN _
> >> & " - Error: File Does Not Exist! - " & Now
> >> End If
> >> ' --------------------------------------------------------
>
> >> Set objFolder = objFSO.GetFolder(S)
> >> Set colFolders = objFolder.SubFolders
> >> For Each sFolder In colFolders
> >> FindFile sFolder, Filename
> >> if FindFile then exit next ' ensure exit from recursion
> >> Next
> >> End Sub
>
> >> As I said, this is not tested (just don't have the time).
> >> Recursive
> >> routines can be tricky and time consuming to test. Hopefully, I
> >> got
> >> it right.
>
> >> Tom Lavedas
> >> ===========http://members.cox.net/tglbatch/wsh/
>
> > This is what i have now....it works, but continues to traverse the
> > subfolders after finding/copying the file.
>
> > Function FindFile(S, F) ' now a function - returns True if found
> > FindFile = False
> > FN = S & "\" & F
> > WScript.Echo "Searching " & S & " for " & F
>
> Assuming that the following statement checks for the file's existence
>
> > If objFSO.FileExists(FN) Then
> > intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> > & FN & " /o administrators", 2, True)
> > If intRunError <> 0 Then
> > WScript.Echo "Error assigning permissions for user " _
> > & strUser & " to file " & FN
> > End If
> > objFSO.copyfile FN, dest & "\" & F, True
>
> Change the following statement
>
> > if FindFile = True then
>
> to
> FindFile = True
>
> > exit Function ' ensure exit from recursion
>
> > end if
>
> > Else
>
> > Set objFolder = objFSO.GetFolder(S)
> > Set colFolders = objFolder.SubFolders
> > For Each sFolder In colFolders
> > FindFile sFolder, Filename
> > if FindFile = True then exit Function ' ensure exit from recursion
> > Next
> > end if
> > End Function

got it....however, that ends the function after recursing through one
subfolder (not the rest) even if it doesn't find the file and copy
it. Here's the latest version.

Function FindFile(S, F) ' now a function - returns True if found
FindFile = False
FN = S & "\" & F
WScript.Echo "Searching " & S & " for " & F
If objFSO.FileExists(FN) Then
intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
& FN & " /o administrators", 2, True)
If intRunError <> 0 Then
WScript.Echo "Error assigning permissions for user " _
& strUser & " to file " & FN
End If
objFSO.copyfile FN, dest & "\" & F, True
FindFile = True
exit Function ' ensure exit from recursion
end if

Set objFolder = objFSO.GetFolder(S)
Set colFolders = objFolder.SubFolders
For Each sFolder In colFolders
FindFile sFolder, Filename
FindFile = True
exit Function ' ensure exit from recursion

Next

End Function

Re: vbscript to traverse subfolders by Pegasus

Pegasus
Thu Mar 13 14:17:36 CDT 2008


"tiv" <jmattivi@gmail.com> wrote in message
news:6ece6459-24be-42a9-8235-9ef38632ed44@i7g2000prf.googlegroups.com...
> On Mar 13, 1:46 pm, "Paul Randall" <paulr...@cableone.net> wrote:
>> "tiv" <jmatt...@gmail.com> wrote in message
>>
>> news:b238f7e0-f6e4-48bc-8ab9-43fe0ef6ca6c@e25g2000prg.googlegroups.com...
>>
>>
>>
>> > On Mar 13, 10:26 am, Tom Lavedas <tglba...@cox.net> wrote:
>> >> On Mar 13, 9:40 am, tiv <jmatt...@gmail.com> wrote:
>>
>> >> > On Mar 12, 6:22 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>>
>> >> > > "tiv" <jmatt...@gmail.com> wrote in message
>>
>> >> > >news:822d8659-5955-42f5-beb4-6980982ac723@e6g2000prf.googlegroups.com...
>>
>> >> > > > On Mar 12, 3:34 pm, "Pegasus \(MVP\)" <I....@fly.com.oz>
>> >> > > > wrote:
>> >> > > >> "tiv" <jmatt...@gmail.com> wrote in message
>>
>> >> > > >>news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
>>
>> >> > > >> > Hey All....
>>
>> >> {snip}
>> >> > YES!!! That does exactly what i want for looking through the
>> >> > subfolders. Thing is, there is only going to be one file per
>> >> > unique
>> >> > name in the entire folder tree. So is there any way that if it
>> >> > finds
>> >> > and copies the file to the destination = true, that it moves on
>> >> > to the
>> >> > next file in the lookup txt file? I've tested and after it finds
>> >> > and
>> >> > copies the file, it continues to look through the subsequent
>> >> > folders
>> >> > for the same file. I'm not sure, but would it need an IF
>> >> > statement
>> >> > and return in the event if the COPY statement is true? Actually
>> >> > after
>> >> > reading this it still sounds unclear....I want it to copy File1
>> >> > from
>> >> > the lookup txt file - "sfile", return to the root of the folders
>> >> > "source" and move to the next file "File2" in the lookup txt -
>> >> > "sfile"
>> >> > and so on and so on. Being that i need to find about 1500 files
>> >> > in
>> >> > "sfile"....
>>
>> >> > THANK YOU so much again! This is invaluable!! (And the
>> >> > permissions
>> >> > to work great as well!!) :)
>>
>> >> I believe the following modifications would do the job (but I
>> >> didn't
>> >> take the time to test it) ...
>>
>> >> Function FindFile(S, F) ' now a function - returns True if found
>> >> FindFile = False
>> >> FN = S & "\" & F
>> >> WScript.Echo "Searching " & S & " for " & F
>> >> If objFSO.FileExists(FN) Then
>> >> ' intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
>> >> ' & FN & " /o administrators", 2, True)
>> >> ' If intRunError <> 0 Then
>> >> ' WScript.Echo "Error assigning permissions for user " _
>> >> ' & strUser & " to file " & FN
>> >> ' End If
>> >> objFSO.copyfile FN, dest & "\" & F, True
>> >> FindFile = True ' return True when found
>> >> exit sub ' stop searching
>> >> Else
>> >> ' --------------------------------------------------------
>> >> ' I don't think this is the right place for this
>> >> ' I believe it puts a log entry for every folder searched
>> >> ' that fails to have the file in it.
>> >> '
>> >> objErrLog.WriteLine FN _
>> >> & " - Error: File Does Not Exist! - " & Now
>> >> End If
>> >> ' --------------------------------------------------------
>>
>> >> Set objFolder = objFSO.GetFolder(S)
>> >> Set colFolders = objFolder.SubFolders
>> >> For Each sFolder In colFolders
>> >> FindFile sFolder, Filename
>> >> if FindFile then exit next ' ensure exit from recursion
>> >> Next
>> >> End Sub
>>
>> >> As I said, this is not tested (just don't have the time).
>> >> Recursive
>> >> routines can be tricky and time consuming to test. Hopefully, I
>> >> got
>> >> it right.
>>
>> >> Tom Lavedas
>> >> ===========http://members.cox.net/tglbatch/wsh/
>>
>> > This is what i have now....it works, but continues to traverse the
>> > subfolders after finding/copying the file.
>>
>> > Function FindFile(S, F) ' now a function - returns True if found
>> > FindFile = False
>> > FN = S & "\" & F
>> > WScript.Echo "Searching " & S & " for " & F
>>
>> Assuming that the following statement checks for the file's existence
>>
>> > If objFSO.FileExists(FN) Then
>> > intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
>> > & FN & " /o administrators", 2, True)
>> > If intRunError <> 0 Then
>> > WScript.Echo "Error assigning permissions for user " _
>> > & strUser & " to file " & FN
>> > End If
>> > objFSO.copyfile FN, dest & "\" & F, True
>>
>> Change the following statement
>>
>> > if FindFile = True then
>>
>> to
>> FindFile = True
>>
>> > exit Function ' ensure exit from recursion
>>
>> > end if
>>
>> > Else
>>
>> > Set objFolder = objFSO.GetFolder(S)
>> > Set colFolders = objFolder.SubFolders
>> > For Each sFolder In colFolders
>> > FindFile sFolder, Filename
>> > if FindFile = True then exit Function ' ensure exit from recursion
>> > Next
>> > end if
>> > End Function
>
> got it....however, that ends the function after recursing through one
> subfolder (not the rest) even if it doesn't find the file and copy
> it. Here's the latest version.
>
> Function FindFile(S, F) ' now a function - returns True if found
> FindFile = False
> FN = S & "\" & F
> WScript.Echo "Searching " & S & " for " & F
> If objFSO.FileExists(FN) Then
> intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> & FN & " /o administrators", 2, True)
> If intRunError <> 0 Then
> WScript.Echo "Error assigning permissions for user " _
> & strUser & " to file " & FN
> End If
> objFSO.copyfile FN, dest & "\" & F, True
> FindFile = True
> exit Function ' ensure exit from recursion
> end if
>
> Set objFolder = objFSO.GetFolder(S)
> Set colFolders = objFolder.SubFolders
> For Each sFolder In colFolders
> FindFile sFolder, Filename
> FindFile = True
> exit Function ' ensure exit from recursion
>
> Next
>
> End Function

Are you saying that the code now does what you expect or not?



Re: vbscript to traverse subfolders by tiv

tiv
Thu Mar 13 14:30:41 CDT 2008

On Mar 13, 3:17 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "tiv" <jmatt...@gmail.com> wrote in message
>
> news:6ece6459-24be-42a9-8235-9ef38632ed44@i7g2000prf.googlegroups.com...
>
>
>
> > On Mar 13, 1:46 pm, "Paul Randall" <paulr...@cableone.net> wrote:
> >> "tiv" <jmatt...@gmail.com> wrote in message
>
> >>news:b238f7e0-f6e4-48bc-8ab9-43fe0ef6ca6c@e25g2000prg.googlegroups.com...
>
> >> > On Mar 13, 10:26 am, Tom Lavedas <tglba...@cox.net> wrote:
> >> >> On Mar 13, 9:40 am, tiv <jmatt...@gmail.com> wrote:
>
> >> >> > On Mar 12, 6:22 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>
> >> >> > > "tiv" <jmatt...@gmail.com> wrote in message
>
> >> >> > >news:822d8659-5955-42f5-beb4-6980982ac723@e6g2000prf.googlegroups.com...
>
> >> >> > > > On Mar 12, 3:34 pm, "Pegasus \(MVP\)" <I....@fly.com.oz>
> >> >> > > > wrote:
> >> >> > > >> "tiv" <jmatt...@gmail.com> wrote in message
>
> >> >> > > >>news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
>
> >> >> > > >> > Hey All....
>
> >> >> {snip}
> >> >> > YES!!! That does exactly what i want for looking through the
> >> >> > subfolders. Thing is, there is only going to be one file per
> >> >> > unique
> >> >> > name in the entire folder tree. So is there any way that if it
> >> >> > finds
> >> >> > and copies the file to the destination = true, that it moves on
> >> >> > to the
> >> >> > next file in the lookup txt file? I've tested and after it finds
> >> >> > and
> >> >> > copies the file, it continues to look through the subsequent
> >> >> > folders
> >> >> > for the same file. I'm not sure, but would it need an IF
> >> >> > statement
> >> >> > and return in the event if the COPY statement is true? Actually
> >> >> > after
> >> >> > reading this it still sounds unclear....I want it to copy File1
> >> >> > from
> >> >> > the lookup txt file - "sfile", return to the root of the folders
> >> >> > "source" and move to the next file "File2" in the lookup txt -
> >> >> > "sfile"
> >> >> > and so on and so on. Being that i need to find about 1500 files
> >> >> > in
> >> >> > "sfile"....
>
> >> >> > THANK YOU so much again! This is invaluable!! (And the
> >> >> > permissions
> >> >> > to work great as well!!) :)
>
> >> >> I believe the following modifications would do the job (but I
> >> >> didn't
> >> >> take the time to test it) ...
>
> >> >> Function FindFile(S, F) ' now a function - returns True if found
> >> >> FindFile = False
> >> >> FN = S & "\" & F
> >> >> WScript.Echo "Searching " & S & " for " & F
> >> >> If objFSO.FileExists(FN) Then
> >> >> ' intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> >> >> ' & FN & " /o administrators", 2, True)
> >> >> ' If intRunError <> 0 Then
> >> >> ' WScript.Echo "Error assigning permissions for user " _
> >> >> ' & strUser & " to file " & FN
> >> >> ' End If
> >> >> objFSO.copyfile FN, dest & "\" & F, True
> >> >> FindFile = True ' return True when found
> >> >> exit sub ' stop searching
> >> >> Else
> >> >> ' --------------------------------------------------------
> >> >> ' I don't think this is the right place for this
> >> >> ' I believe it puts a log entry for every folder searched
> >> >> ' that fails to have the file in it.
> >> >> '
> >> >> objErrLog.WriteLine FN _
> >> >> & " - Error: File Does Not Exist! - " & Now
> >> >> End If
> >> >> ' --------------------------------------------------------
>
> >> >> Set objFolder = objFSO.GetFolder(S)
> >> >> Set colFolders = objFolder.SubFolders
> >> >> For Each sFolder In colFolders
> >> >> FindFile sFolder, Filename
> >> >> if FindFile then exit next ' ensure exit from recursion
> >> >> Next
> >> >> End Sub
>
> >> >> As I said, this is not tested (just don't have the time).
> >> >> Recursive
> >> >> routines can be tricky and time consuming to test. Hopefully, I
> >> >> got
> >> >> it right.
>
> >> >> Tom Lavedas
> >> >> ===========http://members.cox.net/tglbatch/wsh/
>
> >> > This is what i have now....it works, but continues to traverse the
> >> > subfolders after finding/copying the file.
>
> >> > Function FindFile(S, F) ' now a function - returns True if found
> >> > FindFile = False
> >> > FN = S & "\" & F
> >> > WScript.Echo "Searching " & S & " for " & F
>
> >> Assuming that the following statement checks for the file's existence
>
> >> > If objFSO.FileExists(FN) Then
> >> > intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> >> > & FN & " /o administrators", 2, True)
> >> > If intRunError <> 0 Then
> >> > WScript.Echo "Error assigning permissions for user " _
> >> > & strUser & " to file " & FN
> >> > End If
> >> > objFSO.copyfile FN, dest & "\" & F, True
>
> >> Change the following statement
>
> >> > if FindFile = True then
>
> >> to
> >> FindFile = True
>
> >> > exit Function ' ensure exit from recursion
>
> >> > end if
>
> >> > Else
>
> >> > Set objFolder = objFSO.GetFolder(S)
> >> > Set colFolders = objFolder.SubFolders
> >> > For Each sFolder In colFolders
> >> > FindFile sFolder, Filename
> >> > if FindFile = True then exit Function ' ensure exit from recursion
> >> > Next
> >> > end if
> >> > End Function
>
> > got it....however, that ends the function after recursing through one
> > subfolder (not the rest) even if it doesn't find the file and copy
> > it. Here's the latest version.
>
> > Function FindFile(S, F) ' now a function - returns True if found
> > FindFile = False
> > FN = S & "\" & F
> > WScript.Echo "Searching " & S & " for " & F
> > If objFSO.FileExists(FN) Then
> > intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
> > & FN & " /o administrators", 2, True)
> > If intRunError <> 0 Then
> > WScript.Echo "Error assigning permissions for user " _
> > & strUser & " to file " & FN
> > End If
> > objFSO.copyfile FN, dest & "\" & F, True
> > FindFile = True
> > exit Function ' ensure exit from recursion
> > end if
>
> > Set objFolder = objFSO.GetFolder(S)
> > Set colFolders = objFolder.SubFolders
> > For Each sFolder In colFolders
> > FindFile sFolder, Filename
> > FindFile = True
> > exit Function ' ensure exit from recursion
>
> > Next
>
> > End Function
>
> Are you saying that the code now does what you expect or not?

no, it will only traverse one subfolder to look for "file1" then move
back to the root and search for "file2" through one subfolder. It
doesn't traverse all subfolders until it finds the file. I'm pretty
sure it's breaking here below, but just not sure where or how else to
exit the function. right now it's ending the function before finding
the file.

Set objFolder = objFSO.GetFolder(S)
Set colFolders = objFolder.SubFolders
For Each sFolder In colFolders
FindFile sFolder, Filename
FindFile = True
exit Function ' ensure exit from recursion

Re: vbscript to traverse subfolders by Pegasus

Pegasus
Thu Mar 13 14:35:53 CDT 2008


"tiv" <jmattivi@gmail.com> wrote in message
news:efd1b4d4-5a38-4456-9ec5-c81c2bb9806a@h11g2000prf.googlegroups.com...
> On Mar 13, 3:17 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>> "tiv" <jmatt...@gmail.com> wrote in message
>>
>> news:6ece6459-24be-42a9-8235-9ef38632ed44@i7g2000prf.googlegroups.com...
>>
>>
>>
>> > On Mar 13, 1:46 pm, "Paul Randall" <paulr...@cableone.net> wrote:
>> >> "tiv" <jmatt...@gmail.com> wrote in message
>>
>> >>news:b238f7e0-f6e4-48bc-8ab9-43fe0ef6ca6c@e25g2000prg.googlegroups.com...
>>
>> >> > On Mar 13, 10:26 am, Tom Lavedas <tglba...@cox.net> wrote:
>> >> >> On Mar 13, 9:40 am, tiv <jmatt...@gmail.com> wrote:
>>
>> >> >> > On Mar 12, 6:22 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>>
>> >> >> > > "tiv" <jmatt...@gmail.com> wrote in message
>>
>> >> >> > >news:822d8659-5955-42f5-beb4-6980982ac723@e6g2000prf.googlegroups.com...
>>
>> >> >> > > > On Mar 12, 3:34 pm, "Pegasus \(MVP\)" <I....@fly.com.oz>
>> >> >> > > > wrote:
>> >> >> > > >> "tiv" <jmatt...@gmail.com> wrote in message
>>
>> >> >> > > >>news:0d234151-d169-4b27-b64d-d0a0d5d9dd2a@s8g2000prg.googlegroups.com...
>>
>> >> >> > > >> > Hey All....
>>
>> >> >> {snip}
>> >> >> > YES!!! That does exactly what i want for looking through the
>> >> >> > subfolders. Thing is, there is only going to be one file per
>> >> >> > unique
>> >> >> > name in the entire folder tree. So is there any way that if it
>> >> >> > finds
>> >> >> > and copies the file to the destination = true, that it moves on
>> >> >> > to the
>> >> >> > next file in the lookup txt file? I've tested and after it finds
>> >> >> > and
>> >> >> > copies the file, it continues to look through the subsequent
>> >> >> > folders
>> >> >> > for the same file. I'm not sure, but would it need an IF
>> >> >> > statement
>> >> >> > and return in the event if the COPY statement is true? Actually
>> >> >> > after
>> >> >> > reading this it still sounds unclear....I want it to copy File1
>> >> >> > from
>> >> >> > the lookup txt file - "sfile", return to the root of the folders
>> >> >> > "source" and move to the next file "File2" in the lookup txt -
>> >> >> > "sfile"
>> >> >> > and so on and so on. Being that i need to find about 1500 files
>> >> >> > in
>> >> >> > "sfile"....
>>
>> >> >> > THANK YOU so much again! This is invaluable!! (And the
>> >> >> > permissions
>> >> >> > to work great as well!!) :)
>>
>> >> >> I believe the following modifications would do the job (but I
>> >> >> didn't
>> >> >> take the time to test it) ...
>>
>> >> >> Function FindFile(S, F) ' now a function - returns True if found
>> >> >> FindFile = False
>> >> >> FN = S & "\" & F
>> >> >> WScript.Echo "Searching " & S & " for " & F
>> >> >> If objFSO.FileExists(FN) Then
>> >> >> ' intRunError = objShell.Run("%COMSPEC% /c Echo Y| fileacl " _
>> >> >> ' & FN & " /o administrators", 2, True)
>> >> >> ' If intRunError <> 0 Then
>> >> >> ' WScript.Echo "Error assigning permissions for user " _
>> >> >> ' & strUser & " to file " & FN
>> >> >> ' End If
>> >> >> objFSO.copyfile FN, dest & "\" & F, True
>> >> >> FindFile = True ' return True when found
>> >> >> exit sub ' stop searching
>> >> >> Else
>> >> >> ' --------------------------------------------------------
>> >> >> ' I don't think this is the right place for this
>> >> >> ' I believe it puts a log entry for every folder searched
>> >> >> ' that fails to have the file in it.
>> >> >> '
>> >> >> objErrLog.WriteLine FN _
>> >> >> & " - Error: File Does Not Exist! - " & Now
>> >> >> End If
>> >> >> ' --------------------------------------------------------
>>
>> >> >> Set objFolder = objFSO.GetFolder(S)
>> >> >> Set colFolders = objFolder.SubFolders
>> >> >> For Each sFolder In colFolders
>> >> >> FindFile sFolder, Filename
>> >> >> if FindFile then exit next ' ensure exit from recursion
>> >> >> Next
>> >> >> End Sub
>>
>> >> >> As I said, this is not tested (just don't have the time).
>> >> >> Recursive
>> >> >> routines can be tricky and time consuming to test. Hopefully, I
>> >> >> got
>> >> >> it right.
>>
>> >> >> Tom Lavedas
>> >> >> ===========http://members.cox.net/tglbatch/wsh/
>>
>> >> > This is what i have now....it works, but continues to traverse the
>> >> > subfolders after finding/copying the file.
>>
>> >> > Function FindFile(S, F) ' now a function - returns True if found
>> >> > FindFile = False
>> >> > FN = S & "\" & F
>> >> > WScript.Echo "Searching " & S & " for " & F
>>
>> >> Assuming that the fol