+ Post New Thread
Results 1 to 2 of 2
Scripts Thread, VBScript to check if folder exists, then if it does copy a file into it in Coding and Web Development; Hi there, I am trying a write a VB Script to do the following: Check if a folder exists - ...
  1. #1
    rjm
    rjm is offline

    Join Date
    Jun 2008
    Location
    South Yorkshire
    Posts
    24
    Thank Post
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    VBScript to check if folder exists, then if it does copy a file into it

    Hi there,

    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.

    Many thanks!

  2. #2

    Join Date
    Mar 2011
    Location
    Coventry
    Posts
    61
    Thank Post
    12
    Thanked 6 Times in 6 Posts
    Rep Power
    9
    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 :-)



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 17
    Last Post: 20th March 2010, 12:51 AM
  2. vbscript to copy a folder & delete a folder
    By MicrodigitUK in forum Scripts
    Replies: 2
    Last Post: 29th January 2009, 01:43 PM
  3. ...\NetSupport School\NSM.LIC (80). Please check this file exists and is valid.
    By akwok in forum Network and Classroom Management
    Replies: 5
    Last Post: 28th May 2008, 10:01 AM
  4. Replies: 4
    Last Post: 23rd March 2006, 07:27 AM
  5. Replies: 3
    Last Post: 1st March 2006, 01:08 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •