On windows 7 x64 with a batch files (*.bat):
I need to check in a folder the last file (less than 5 days) and path to add in Mycommand as argument.
I need i think :
"FORFILES -5" perhaps "Call"
i begin with :
@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)
How to output like that :
D:\\stockage\\Mycommand -a D:\\temp\\file.jpg -a D:\\temp\\file2.jpg -a D:\\temp\\file3.jpg etc...
don't put non existing file or blank argument, i think i must Loop the argument "-a D:\\temp\\filexxx.jpg" but i don't know how to do it.
And if possible escape file name probleme more than x chars or space inside.
Can you give me an example ?
Thank.
echo
produces a linefeed and you can not stop it from doing so. As an alternative, first assemble the complete line:
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%
This gives you the latest 5 files (or fewer, if the folder has not enough files)
Edited to reverse the order of the Parameters:
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%
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.