|
-
Apr 7th, 2012, 02:47 PM
#1
Thread Starter
New Member
User Input Directed Search Of Folders and SubFolders, Copy File To Different Folder
I have searched for my answer, looked at little pieces here and there, but haven't hit the nail on the head.
Everyday we have 4 files (2 AM, and 2 PM), both divided into two different work locations. We need to archive those 4 files into our workgroups local drive. Now each day the filename contains that days date. So for today AM we have: Time Exception A 4-7-2012 and Time Exception B 4-7-2012, and PM we have Time Exception A 4-7-2012 and Time Exception B 4-7-2012. All four files are located in different folders. Folder paths:
AM:
Time Exception A 4-7-2012:
S:\ABCSharedFolders\OOC\spOvA\ES\ABC\PSD\AM Time Exception\PP #7\
Time Exception B 4-7-2012:
S:\ABCSharedFolder\OOC\spOvA\ES\ABC\BSD\AM FILES\AM Time Exception\PP-07\
PM:
Time Exception A 4-7-2012
S:\ABCSharedFolders\OOC\spOvA\ES\ABC\PSD\PM Time Exception\PP 7-12\
Time Exception B 4-7-2012
S:\ABCSharedFolders\OOC\spOvA\ES\ABC\BSD\PM FILES\PM Time Exceptions\PP #07 - 2012\
One problem that we run into as you can see is that the consistancy is lost when these workgroups name their folders. That is why having some code that will search the subdirectories is critical since we do have consistancy all the way up to PSD and BSD folders.
Once we can confirm that the file exists, it will have to be copied and pasted to our workgroups folder. The path for this is:
AM:
Time Exception A 4-7-2012:
Z:\ABC\ABC Field\COSA\Time Exception Archive\2012 Archive\A\April\AM\
Time Exception B 4-7-2012:
Z:\ABC\ABC Field\COSA\Time Exception Archive\2012 Archive\B\April\AM\
PM:
Time Exception A 4-7-2012
Z:\ABC\ABC Field\COSA\Time Exception Archive\2012 Archive\A\April\PM\
Time Exception B 4-7-2012
Z:\ABC\ABC Field\COSA\Time Exception Archive\2012 Archive\B\April\PM\
If possible, we would like the "user input" or search function to only look for the date in the filename just in case someone gets the need to save the file with a funky name, at least we know the date will always be there.
Here is what I have found so far. I know it is nowhere near what I need, but overall I liked the functionallity of it. It will only search for specific, whole, filenames and that we wont have.
Code:
Sub CopySomeFiles()
Dim FSO, sourceFolder, currentFile, filesInSourceFolder
Dim strSourceFolderPath As String
Dim strDestinationFolderPath As String
Dim strUserInput As String
Set FSO = CreateObject("Scripting.FileSystemObject")
' Figure out which file to copy from where to where
strUserInput = InputBox("Please enter name of file to copy.")
strSourceFolderPath = "C:\MySourceFolder"
strDestinationFolderPath = "C:\MyDestinationFolder"
Set sourceFolder = FSO.GetFolder(strSourceFolderPath)
Set filesInSourceFolder = sourceFolder.Files
' Look at all files in source folder. If name matches,
' copy to destination folder.
For Each currentFile In filesInSourceFolder
If currentFile.Name = strUserInput Then
currentFile.Copy (FSO.BuildPath(strDestinationFolderPath, _
currentFile.Name))
End If
Next
End Sub
I hope I explained this in a manner that can be followed. It is a lot of information. Please let me know if I can elaborate any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|