简体   繁体   中英

Storing output of batch command (forfiles) into variable

i am running the following command from cmd.exe using batch file.

forfiles /p C:\Users\subhamt\Downloads /m embeddedsection.zip /c "cmd /c echo @fsize"

what i wish to do is that i want to save the output of the command in to a variable for that i changed the above command to :

set var=forfiles /p C:\Users\subhamt\Downloads /m embeddedsection.zip /c "cmd /c echo @fsize"

but when i do on echo on var then it gives me the above commadnd itself as an output. can someone please point what i am doing wrong.

i went through the following links and some more but they didnt solve the problem i have at hand.

Can I store the output of a command in a variable in batch scripting?

passing variables with forfiles command

for %%a in (C:\Users\subhamt\Downloads\embeddedsection.zip) do set var=%%~za

should return the filesize of C:\\Users\\subhamt\\Downloads\\embeddedsection.zip for you in var

(this is a batch line. If executing directly from the prompt, reduce each %% to % )

可能的解决方案:

for /f %%i in ('forfiles /p C:\Users\subhamt\Downloads /m embeddedsection.zip /c "cmd /c echo @fsize"') do set FILE_SIZE_WINDOWS=%%i

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM