+ Post New Thread
Results 1 to 5 of 5
Scripts Thread, Copy a folder to c drive only if it doesn't exist in Coding and Web Development; Hi all, What I'm trying to do is create a .bat or .vbs script that will copy a folder from ...
  1. #1

    bladedanny's Avatar
    Join Date
    May 2009
    Location
    Sheffield
    Posts
    1,289
    Thank Post
    190
    Thanked 307 Times in 229 Posts
    Rep Power
    131

    Copy a folder to c drive only if it doesn't exist

    Hi all,

    What I'm trying to do is create a .bat or .vbs script that will copy a folder from the network to c:\program files. I can do this no problem, what I want to know is how can I copy the folder only if it doesn't already exist in c:\program files.

    I'm new to IF functions in scripts so any help is welcomed.

    Also if possible I would prefer a .bat file rather than .vbs.

    Thanks,

    Dan

  2. #2

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,069
    Thank Post
    210
    Thanked 430 Times in 310 Posts
    Rep Power
    144
    This should do the trick - it's VBS script.

    Code:
    Const OverWriteFiles = True
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    If Not objFSO.FolderExists("c:\folder\path\here") then 
    objFSO.CopyFolder "\\server\share\foldername" , "C:\folder\path\here" , OverWriteFiles
    End if

  3. Thanks to maniac from:

    bladedanny (13th October 2009)

  4. #3
    Newton's Avatar
    Join Date
    Oct 2007
    Posts
    179
    Thank Post
    59
    Thanked 5 Times in 5 Posts
    Rep Power
    15
    Try

    IF [NOT] EXIST filename command

  5. Thanks to Newton from:

    bladedanny (13th October 2009)

  6. #4

    bladedanny's Avatar
    Join Date
    May 2009
    Location
    Sheffield
    Posts
    1,289
    Thank Post
    190
    Thanked 307 Times in 229 Posts
    Rep Power
    131
    Thanks, both work great, I have gone for the VBS one as I have heard they are better? Only reason I asked for .bat is because I have more knowledge of .bats.

    Thanks,

    Dan

  7. #5

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,157
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    vbscript has more facilities available (particularly when you start working with COM objects like the filesystem, network, shell, active directory and so on) than batch language and I find it way more readable

    batch language used to be good because you could be sure that a command interpreter was always available but given that vbscript has been standard on Windows since IE4 came out you can be pretty sure it's going to be available on most machines.

    There are arguments for doing it all in something like Perl - you've then got a pretty cross platform language. I'm afraid I don't accept those arguments; Perl is a nightmare language for people with brains far bigger than me :-)

  8. Thanks to srochford from:

    bladedanny (13th October 2009)

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 5
    Last Post: 29th January 2013, 10:16 AM
  2. Folder redirection through GPOs doesn't work
    By cjohnsonuk in forum Windows
    Replies: 2
    Last Post: 3rd September 2009, 04:14 PM
  3. vbscript to copy a folder & delete a folder
    By MicrodigitUK in forum Scripts
    Replies: 2
    Last Post: 29th January 2009, 12:43 PM
  4. Replies: 3
    Last Post: 18th August 2008, 01:59 PM
  5. Replies: 2
    Last Post: 1st October 2005, 02:55 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
  •