• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 849
  • Last Modified:

vbs script to copy folder and create dir and folder if not exist

Hi, i require a vbs script for the following,please help ,thank you:
if not exist c:\rock md c:\rock
if not exist copy  c:\windows\ copy \\networkshare\xx.doc c:\windows\ /Y
0
Shankar3003
Asked:
Shankar3003
  • 4
  • 4
1 Solution
 
SriVaddadiCommented:
Add a reference to Microsoft Scripting Runtime and Use File System Object. You could do all the stuff you mentioned.

Dim fso as new FileSystemObject

fso.FolderExists
fso.CreateFolder
fso.CopyFile
0
 
Shankar3003Author Commented:
i am not that good with vbs script can you show me a sample script, thank you.
0
 
SriVaddadiCommented:
Where are you writing your vbs? Is it from VB IDE or Excel  or any other IDE?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Shankar3003Author Commented:
notepad
0
 
SriVaddadiCommented:
// Instantiate a File System ActiveX Object:
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (not fso.FolderExists("c:\rock "))
fso.CreateFolder("c:\rock ")
end if
if not fso.FileExists("c:\windows\xx.doc") then
fso.copyfile "\\networkshare\xx.doc", "c:\windows\xx.doc"
end if
0
 
SriVaddadiCommented:
Was the solution helpful?
0
 
Shankar3003Author Commented:
HI Sri, i have tried to place it in my current vbs script but it seem not to work. I cannot seem to create or copy although permission and admin access is there.
0
 
Shahan AyyubSenior Software Engineer - iOSCommented:
Try this one:


Option Explicit
Dim objFSO, objFolder, objShell,  strDirectory
strDirectory = "c:\logs"

' Create the File  System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'  Note If..Exists. Then, Else ... End If construction
If  objFSO.FolderExists(strDirectory) Then
   Set objFolder =  objFSO.GetFolder(strDirectory)
   WScript.Echo strDirectory & "  already created "
Else
   Set objFolder =  objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " &  strDirectory
End If

If err.number = vbEmpty then
   Set  objShell = CreateObject("WScript.Shell")
   objShell.run ("Explorer"  &" " & strDirectory & "\" )
Else WScript.echo  "VBScript Error: " & err.number
End If

WScript.Quit


Found from here: Click to see
0
 
Shankar3003Author Commented:
done
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now