VBScript XCopy to local disk not working -



VBScript XCopy to local disk not working -

i trying develop simple script copies files specific drives.

the script following:

check physical drive letter if drive exists re-create files. if no drive move step 2. check network drive letter if drive exists re-create files. if no drive move step 3. create new network mapping copy files drive

when network drive exists, or network mapped drive created via script xcopy commands works perfectly. problem step 1 , local drive exists, no files copied drive after calling xcopy.

here code:

strlocaldrive = "e:" strremoteshare = "\\127.0.0.1\c$\program files (x86)\myfolder\edrive" bolfoundexisting = false source = "c:\program files (x86)\myfolder\edrive\*" destination = "e:\" ' check parameters passed create sense if right(strlocaldrive, 1) <> ":" or left(strremoteshare, 2) <> "\\" 'wscript.echo "usage: cscript mapdrive.vbs drive fileshare //nologo" wscript.quit(1) end if 'wscript.echo " - mapping: " + strlocaldrive + " " + strremoteshare 'set objnetwork = wscript.createobject("wscript.network") set objnetwork = createobject("wscript.network") set oshell = createobject("wscript.shell") set objfso = createobject("scripting.filesystemobject") ' loop through network drive connections , disconnect match strlocaldrive set objdrives = objnetwork.enumnetworkdrives ' first check physical drive not exist if objfso.driveexists(strlocaldrive) wscript.echo "physical drive found" bolfoundexisting = true elseif objdrives.count > 0 = 0 objdrives.count-1 step 2 if objdrives.item(i) = strlocaldrive strshareconnected = objdrives.item(i+1) 'objnetwork.removenetworkdrive strlocaldrive, true, true i=objdrives.count-1 bolfoundexisting = true end if next end if if bolfoundexisting <> true wscript.echo "drive not exists" set objreg = getobject("winmgmts:{impersonationlevel=impersonate}!\\.\root\default:stdregprov") objreg.getstringvalue hkcu, "network\" & left(strlocaldrive, 1), "remotepath", strshareconnected if strshareconnected <> "" set objreg = nil bolfoundremembered = true end if 'now drive map (not persistent) err.clear on error resume next objnetwork.mapnetworkdrive strlocaldrive, strremoteshare, false else ' drive exists re-create files wscript.echo "drive exists" oshell.run "xcopy.exe " & source & " " & destination & " /c /d /e /h /i /k /r /s /y" set oshell = nil end if

i appreciate if 1 explain why xcopy command copies files network drives , not local drives! tia!

update have realized problem beingness caused spaces in path name. unusual copying network drives work, not physical drives. how can handle spaces in path name?

your paths have spaces in them wont expand running xcopy command. much in same way need utilize quotes on command line need quote strings .run. preferred way of inserting double quotes using chr(34). 34 beingness ansi code double quotes

a simple illustration chr(34) & "quotedstring" & chr(34). case utilize this:

oshell.run "xcopy.exe " & chr(34) & source & chr(34) & " " & chr(34) & destination & chr(34) & " /c /d /e /h /i /k /r /s /y"

for readabilty can utilize underscore break lines

oshell.run "xcopy.exe " & chr(34) & source & chr(34) & " " & _ chr(34) & destination & chr(34) & _ " /c /d /e /h /i /k /r /s /y"

vbscript xcopy filesystemobject

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -