I am trying a write a VB Script to do the following:
Check if a folder exists - if it doesn't END
- If it does check if two files exist within it
- if they do END
- if they don't, copy the two files
Basically I want to check that two files exist within a folder of some software that might be installed. I want to copy the two files if the software is installed, but not if the software isnt installed.
Hope that makes sense, and any help is greatly appreciated.
along the lines of............
.........?Code:folderPath = "D:\FolderPath" 'Path of the folder to check (Do not add a \ at the end off the variable) file1 = "file1.ext" 'Name and extension of 1st file to check file2 = "file2.ext" 'Name and extension of 2nd file to check copyLocation = "D:\CopyLocation" 'location of files to copy from if they dont exist (Do not add a \ at the end off the variable) Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FolderExists(folderPath) Then 'Check to see if the files were found and if not copy the one that wasnt found (Or both) If objFSO.FileExists(folderPath & "\" & file1) = False Then objFSO.CopyFile copyLocation & "\" & file1, folderPath & "\" & file1, false End If If objFSO.FileExists(folderPath & "\" & file2) = False Then objFSO.CopyFile copyLocation & "\" & file2, folderPath & "\" & file2, false End If End If
I have very quickly tested it using local paths. Network paths should also work though.
It might not be the neatest script in the world but I just threw it together quickly while I wait for a VM to install.
Last edited by iMash; 5th April 2011 at 06:26 PM. Reason: Alot shorter code :-)
There are currently 1 users browsing this thread. (0 members and 1 guests)