在實(shí)際應(yīng)用中,發(fā)現(xiàn)了一個(gè)問(wèn)題,vbs跨盤(pán)移動(dòng)文件夾無(wú)權(quán)限,權(quán)限拒絕,但是copy就可以。可以采用變通的辦法先復(fù)制再刪除
跨盤(pán)移動(dòng)文件夾的怪問(wèn)題
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\Scripts" , "d:\2"
權(quán)限拒絕,但是copy就可以??梢圆捎米兺ǖ霓k法先復(fù)制再刪除
===========================wmi==============================
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = objFolder.Rename("d:\\VBScript")
Wscript.Echo errResults
Next
錯(cuò)誤碼13,估計(jì)是更名的時(shí)候不允許ren c:\1 d:\2這樣的格式
========================Shell.Application可以成功====================
Const FOF_CREATEPROGRESSDLG = &H0&
TargetFolder = "c:\3"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(TargetFolder)
objFolder.MoveHere "d:\downloads", FOF_CREATEPROGRESSDLG
但是必須目標(biāo)文件夾(像本例的是c:\3)存在才可以