?
Solved

vbscript copy file

Posted on 2011-05-02
9
Medium Priority
?
502 Views
Last Modified: 2012-05-11
Copy file relative path
I want to be able to copy file from curent folder to c:/script

example set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(".\\downloads\sysprep.xml") Then
   filesys.CopyFile ".\\downloads\sysprep.xml", "c:\cript\"

but is not working right now, can anyone help please
0
Comment
Question by:Watulinks
9 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 35508307
Does c:\cript exist?  (should it be c:\script instead?)
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35508314
... and you need End IF after the copy statement
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35508330
also, specify a full path for the source, so instead of this:

   ".\\downloads\sysprep.xml"

use something like this:

   "c:\users\downloads\sysprep.xml"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Watulinks
ID: 35508405
yes want to be able to run it off the thumbdrive or from the current location and be able to copy the file to c:drive.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35508752
So you may not know the drive letter, but you should know the full path on the thumb drive, correct?

so use:   "\myfolder\mysub\downloads\sysprep.xml"
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35508764
so, combining all that I know from above:

If  filesys.FileExists("\myfolder\sub\downloads\sysprep.xml")  Then
    filesys.CopyFile  "\myfolder\sub\downloads\sysprep.xml",  "c:\script\"
End If
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35508769
... but of course, this assumes that the current working directory is on the thumb drive.
0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 1000 total points
ID: 35509236
How about this?

Set objFSO = CreateObject("Scripting.FileSystemObject")
strCurDir = objFSO.GetAbsolutePathName(".")
strFile = strCurDir & "\downloads\sysprep.xml"
If objFSO.FileExists(strFile) Then objFSO.CopyFile strFile, "c:\cript\"

Open in new window

~bp
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35509718
If the VBS you are running is on the root of the USB drive (say E:\), and you want to copy files from E:\Downloads to C:\Scripts, then you can try this.

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strCurrentDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
If Right(strCurrentDir, 1) = "\" Then strCurrentDir = Left(strCurrentDir, Len(strCurrentDir) - 1)
If objFSO.FileExists(strCurrentDir & "\downloads\sysprep.xml") Then
	objFSO.CopyFile strCurrentDir & "\downloads\sysprep.xml", "c:\script\", True
End If

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question