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