![](/img/trans.png)
[英]How to write command in windows batch file to copy a zip file from an FTP path to a local folder in my computer
[英]How to write multiple path and file of a folder in once command line argument dos batch
在具有批處理文件(* .bat)的Windows 7 x64上:
我需要檢查文件夾中的最后一個文件(少於5天)和要添加到Mycommand中作為參數的路徑。
我需要我認為:
“檔案-5”或“通話”
我開始:
@echo off
REM
set folder="D:\temp"
set vararg="-a"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (D:\stockage\Mycommand %vararg% %folder%\\"%%i" -v > c:\temp\test_log.txt)
如何這樣輸出:
D:\\ stockage \\ Mycommand -a D:\\ temp \\ file.jpg -a D:\\ temp \\ file2.jpg -a D:\\ temp \\ file3.jpg等...
不要放入不存在的文件或空白參數,我想我必須循環參數“ -a D:\\ temp \\ filexxx.jpg”,但我不知道該怎么做。
如果可能的話,轉義文件名可能會超過x個字符或內部空格。
你能舉個例子嗎 ?
謝謝。
echo
產生換行符,您不能停止它。 或者,首先組裝完整的行:
setlocal enabledelayedexpansion
set commandline="D:\stockage\Mycommand"
set maxfiles=5
for /f "delims=" %%i in ('dir /b /o-d') do (
set /a maxfiles-=1
set commandline=!commandline! -a "%%i"
if !maxfiles! leq 0 goto :enough
)
:enough
echo %commandline%
這將為您提供最新的5個文件(如果文件夾沒有足夠的文件,則為更少)
編輯以反轉參數的順序:
setlocal enabledelayedexpansion
set "commandline="
set maxfiles=5
for /f "delims=" %%i in ('dir /b /o-d') do (
set /a maxfiles-=1
set commandline=-a "%%i" !commandline!
if !maxfiles! leq 0 goto :enough
)
:enough
set commandline="D:\stockage\Mycommand" %commandline%
echo %commandline%
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.