You are not logged in.
Pages: 1
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
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
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
Thank you for quick answers, but none of those don't work both do the targetdit.txt file but it's empty.
Offline
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
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!!!!!!!!!
Offline
Pages: 1