vbscript copy file

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
WatulinksAsked:
Who is Participating?
 
Bill PrewCommented:
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
 
knightEknightCommented:
Does c:\cript exist?  (should it be c:\script instead?)
0
 
knightEknightCommented:
... and you need End IF after the copy statement
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
knightEknightCommented:
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
 
WatulinksAuthor Commented:
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
 
knightEknightCommented:
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
 
knightEknightCommented:
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
 
knightEknightCommented:
... but of course, this assumes that the current working directory is on the thumb drive.
0
 
RobSampsonCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.