Problem with set /A

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tmboredi
Posts: 3
Joined: 04 Jan 2012 12:25

Problem with set /A

#1 Post by tmboredi » 04 Jan 2012 12:34

Hi guys,

Is there something wrong with my set statement? I'm getting "The system cannot find the file specified."
But dir /a /s /OG D:\FYP\piclog |find /v "<DIR>" | find /c "M" alone returns a proper integer value, 21 etc.



set /A count="dir /a /s /OG D:\FYP\piclog |find /v "<DIR>" | find /c "M""

echo.%count%

aGerman
Expert
Posts: 3886
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Problem with set /A

#2 Post by aGerman » 04 Jan 2012 13:50

Use a FOR /F loop to receive a value from a command line:

Code: Select all

for /f %%i in ('dir /a /s /OG D:\FYP\piclog |find /v "<DIR>" ^| find /c "M"') do set /a count=%%i

Regards
aGerman

tmboredi
Posts: 3
Joined: 04 Jan 2012 12:25

Re: Problem with set /A

#3 Post by tmboredi » 05 Jan 2012 10:15

Thanks! but my command prompt window closes right after it runs, even with a pause at the end. Any idea what is wrong?

EDIT: It says | was unexpected at this time. :?

Squashman
Expert
Posts: 4176
Joined: 23 Dec 2011 13:59

Re: Problem with set /A

#4 Post by Squashman » 05 Jan 2012 11:29

Missing a Carrot before the first pipe.

tmboredi
Posts: 3
Joined: 04 Jan 2012 12:25

Re: Problem with set /A

#5 Post by tmboredi » 05 Jan 2012 11:53

done! sorry i'm new at this, you guys are great :)

Post Reply