2

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

Community
  • 1
  • 1
Subham Tripathi
  • 2,683
  • 6
  • 41
  • 70
  • 1
    An environment variable can only store one value unless you allow separators. Try saying what you want to do, not how you want to do it. If all you want is the filesize for a set of files, there are easier ways. – Magoo Dec 12 '14 at 05:34
  • ok, ya i basically want to find file size. @Magoo – Subham Tripathi Dec 12 '14 at 05:38

2 Answers2

3
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 %)

Magoo
  • 77,302
  • 8
  • 62
  • 84
1

Possible solution :

for /f %%i in ('forfiles /p C:\Users\subhamt\Downloads /m embeddedsection.zip /c "cmd /c echo @fsize"') do set FILE_SIZE_WINDOWS=%%i
Subham Tripathi
  • 2,683
  • 6
  • 41
  • 70