Script don't find only in system partition...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
JuanMa777
Posts: 17
Joined: 06 Nov 2016 13:15
Location: La Plata, ¡Argentina!

Script don't find only in system partition...

#1 Post by JuanMa777 » 06 Nov 2016 13:52

Hi,
I'm having a little and y hope so simple trouble.
I need to find with dir and findstr files with .aes extension.
The problem is that when I put this in a for loop the script not find my files in my system partition (c: in this case)...
When I put in the console

Code: Select all

for /f %x in ('dir /b /s c: ^| findstr /e ".aes"') do echo %x
works all fine, but when I put this in a script don't work...
Obviusly that I use double % for x, but nothing...
The same script with d: works perfect!
It's more strange.
Any sugestion...
Thanks.

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

Re: Script don't find only in system partition...

#2 Post by aGerman » 07 Nov 2016 01:42

Append a backslash to C: and you have to double the percent signs of the FOR variables in a batch script. Also use "delims=" in order to display all tokens if the path contains spaces.

Code: Select all

for /f "delims=" %%x in ('dir /b /s c:\ ^| findstr /e ".aes"') do echo %%x

Since you can use wildcards with DIR it could be simplified

Code: Select all

for /f "delims=" %%x in ('dir /b /s c:\*.aes') do echo %%x

Steffen

JuanMa777
Posts: 17
Joined: 06 Nov 2016 13:15
Location: La Plata, ¡Argentina!

Re: Script don't find only in system partition...

#3 Post by JuanMa777 » 07 Nov 2016 06:09

Thanks man, I got the same answer.
The complementary answer is usefull, but my script needs to parse all the partitions, and I tried and I think that not work. Anyway this point is solved.
I close the topic in general.
Thanks.

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

Re: Script don't find only in system partition...

#4 Post by aGerman » 07 Nov 2016 06:30

JuanMa777 wrote:my script needs to parse all the partitions

That should also work.

Code: Select all

for %%d in (C D E) do (
  for /f "delims=" %%x in ('dir /b /s %%d:\*.aes') do echo %%x
)

... where C D E is the list of drive letters of your partitions.

Steffen

JuanMa777
Posts: 17
Joined: 06 Nov 2016 13:15
Location: La Plata, ¡Argentina!

Re: Script don't find only in system partition...

#5 Post by JuanMa777 » 07 Nov 2016 07:04

I'll try, I get only the logical disk through wmic. The issue is that I need several file extensions.
Thanks.

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

Re: Script don't find only in system partition...

#6 Post by Squashman » 07 Nov 2016 07:36

You can put multiple file masks into the dir command.

Code: Select all

for %%d in (C D E) do (
    PUSHD %%d:\
    for /f "delims=" %%x in ('dir /b /s *.aes *.txt *.etc') do echo %%x
    POPD
)

Post Reply