我不能为我的生活让这个工作正常。发生的事情是我正在将.vbs文件写入%temp%文件夹作为帮助文件。然后我打电话给它。除了单个“)”角色没有结转之外,它一切正常。
set "path=\\server1\folder\folder\folder\dest-folder"
set source=^"%path%\nwm*.zip^"
set destination=%path%
setlocal
for /f "tokens=* delims=" %%a in ('dir/b "%destination%\nwm*.zip"') do (
set source=%%a
:unzip
>> %temp%\unzip.vbs echo ^'test
>> %temp%\unzip.vbs echo call WindowsUunzip(%source%,"%destination%")
>> %temp%\unzip.vbs echo Function WindowsUunzip(sUunzipFileName, sUunzipDestination)
C:\windows\system32\cscript //nologo %temp%\unzip.vbs
pause
if exist "%temp%\unzip.vbs" del /f /q "%temp%\unzip.vbs"
endlocal
)
这是我得到的结果:
'test
call WindowsUunzip("\\server1\folder\folder\folder\dest-folder\nwm*.zip","\\server1\folder\folder\folder\dest-folder"
Function WindowsUunzip(sUunzipFileName, sUunzipDestination)
这是我希望在结尾的第一行看到(A“)”符号的结果。)
'test
call WindowsUunzip("\\server1\folder\folder\folder\dest-folder\nwm*.zip","\\server1\folder\folder\folder\dest-folder")
Function WindowsUunzip(sUunzipFileName, sUunzipDestination)
到目前为止我尝试过的:
set "Xpath=\\server1\folder\folder\folder\dest-folder"
set source=^"%Xpath%\nwm*.zip^"
set destination=%Xpath%
setlocal
for /f "tokens=* delims=" %%a in ('dir/b "%destination%\nwm*.zip"') do (
>> %temp%\unzip.vbs echo ^'test
>> %temp%\unzip.vbs echo call WindowsUunzip(%%a,"%destination%"^)
>> %temp%\unzip.vbs echo Function WindowsUunzip(sUunzipFileName, sUunzipDestination^)
C:\windows\system32\cscript //nologo %temp%\unzip.vbs
pause
if exist "%temp%\unzip.vbs" del /f /q "%temp%\unzip.vbs"
)
endlocal
PATH是Windows搜索的目录序列,用于查找当前目录中找不到的可执行文件。你改变它是危险的。
您是否知道set
命令之前的值setlocal
是永久性的set
进入此会话的环境?
在source
目录扫描中检查destination
而不是for /f
文件更为正常。
在for
循环中使用标签几乎可以保证给您带来麻烦。我怀疑你已经在goto unzip
循环中审查了(在生成最小脚本时完全可以接受)一个重要的for
语句(你不能在goto
循环中使用for
目的地。)
并且你的endlocal
应该在for
循环之外,否则它会被调用用于调用的每个循环值。
最后,你知道吗?
> %temp%\unzip.vbs echo ^'test
(注意单个>
)将启动一个新文件%temp%\unzip.vbs
,替换任何现有版本?这可能会为你节省门控删除(但是你需要在for
循环关闭后删除文件[如果你愿意])
这是我认为你想要做的batch-file选项:
<!-- :
@Echo Off
Set "destination=\\server1\folder\folder\folder\dest-folder"
Set "file-mask=nwm*.zip"
For /F "Delims=" %%A In ('Where "%destination%":"%file-mask%"'
)Do CScript //NoLogo "%~f0?.wsf" "%%A" "%destination%"
Exit /B
-->
<Job><Script Language="VBScript">
Unzip WScript.Arguments(0), WScript.Arguments(1)
Sub Unzip(sSource, sTargetDir)
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(sTargetDir) Then oFSO.CreateFolder(sTargetDir)
Set oShell = CreateObject("Shell.Application")
Set oSource = oShell.NameSpace(sSource).Items()
Set oTarget = oShell.NameSpace(sTargetDir)
oTarget.CopyHere oSource, 256
End Sub
</Script></Job>
你可以明显地调整你的VBScript
代码以适合你的确切目的,但这应该为你提供一种方法。