Page 1 of 1

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

Posted: 06 Nov 2016 13:52
by JuanMa777
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.

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

Posted: 07 Nov 2016 01:42
by aGerman
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

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

Posted: 07 Nov 2016 06:09
by JuanMa777
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.

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

Posted: 07 Nov 2016 06:30
by aGerman
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

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

Posted: 07 Nov 2016 07:04
by JuanMa777
I'll try, I get only the logical disk through wmic. The issue is that I need several file extensions.
Thanks.

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

Posted: 07 Nov 2016 07:36
by Squashman
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
)