You are not logged in.

#1 05 Jan 2015 17:39

hozza
Member
Registered: 05 Jul 2014
Posts: 27

Little help please!

I have this script and it almost work like i want but not not quite!
it does the job but it prints every time when it find's drive:letter that exist even if there is not that file what i'm search for!
example: this file is located C:\NewFolder\Filename.exe and my computer have drive's: C D E
targetdir.txt contains three time's line: C:\NewFolder\      and i want that it's there only once!
                                                       C:\NewFolder\
                                                       C:\NewFolder\

Please HELP ME to get this working

For %%d in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do                                     (
    %%d:
    cd \
    for /R %%A in ("Filename.exe?") do (echo:%%~DPA) >> "C:\Temp\targetdir.txt"
)
pause
exit

Last edited by hozza (05 Jan 2015 17:52)

Offline

#2 05 Jan 2015 19:38

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Little help please!

A common error is that the file already exists with text inside it when running another test.

But try this:

@echo off
For %%d in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if exist "%%d:\" (cmd /c for /R "%%d:\" %%A in ("Filename.exe?") do echo(%%~DPA)>"C:\Temp\targetdir.txt"
pause
exit

Offline

#3 06 Jan 2015 08:13

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: Little help please!

for /r has some quirky behaviour, which is often undesirable (some might say buggy); I usually end up using "for /f", like so:

@echo off
type nul > "C:\Temp\targetdir.txt"
for %%d in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do                                     (
    for /f "usebackq tokens=*" %%A in (`dir /b/s/a:-d "%%d:\Filename.exe" 2^>nul`) do (echo:%%~DPA) >> "C:\Temp\targetdir.txt"
)
pause
exit

Last edited by bluesxman (06 Jan 2015 08:14)


cmd | *sh | ruby | chef

Offline

#4 06 Jan 2015 14:04

hozza
Member
Registered: 05 Jul 2014
Posts: 27

Re: Little help please!

Thank you for quick answers, but none of those don't work both do the targetdit.txt file but it's empty.

Offline

#5 06 Jan 2015 16:57

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Little help please!

Yes, my suggestion fails, but the code above from bluesxman works fine.

Here is another one that works.

@echo off
(
For %%d in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if exist "%%d:\" (
   echo processing drive %%d 1>&2
   pushd "%%d:\" 
      for /r %%e in ("Filename.exe?") do echo(%%~dpe
   popd
)
)>"C:\Temp\targetdir.txt"
pause
exit

Offline

#6 06 Jan 2015 18:27

hozza
Member
Registered: 05 Jul 2014
Posts: 27

Re: Little help please!

Yes you are right that Bluesxman's code did work for some reason it did'nt first time ques I did something wrong what i did'nt noticed!

but that last one is very very nice, thank you both very much!
this is every thing I needed and some more!!!!!!!!!
smile  smile  smile  smile

Offline

Board footer

Powered by