Computing.Net > Forums > Programming > batch search f. and go to that dir

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch search f. and go to that dir

Reply to Message Icon

Name: Alatar
Date: July 14, 2007 at 16:46:17 Pacific
OS: Windows XP SP2
CPU/Ram: P4 2,8Ghz / 1Gb
Comment:

hi
i'm getting crazy with this matter... i would want to make a file batch that could search for a specific file (for example a file named abc.dat) and then assign to a variable the path of that file or could only go to to the directory containing it. It should be great to restrict search to one level subdirectory only... i know that there was an utility called "berkfind" that was able to do exactly this, but it is not compatible with Windows XP.
ps: sorry if my english sucks but it's not my main language...



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: July 14, 2007 at 18:04:29 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/s/b/a-s c:\temp\abc.dat') do (
set var=%%~DPa
echo the path to abc.dat is !var!
)


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 2
Name: Alatar
Date: July 15, 2007 at 03:42:51 Pacific
Reply:

mitico! :-)
i had to delete the string "c:\temp\" leaving only 'dir/s/b/a-s abc.dat'
and it's ok!!
thanks!

do you have any idea on how limit the search in the subdir to only the first level?


0

Response Number 3
Name: Mechanix2Go
Date: July 15, 2007 at 04:36:29 Pacific
Reply:

I think you mean that if the tree is:


S:\MY
├───a
│ ├───1
│ └───2
└───b
├───1
└───2

[that got trashed as usual]

I think you want to start at MY and check a and b but NOT 1 and 2. Is that right?



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 4
Name: Alatar
Date: July 15, 2007 at 05:10:52 Pacific
Reply:

exactly
do you know how to make it?


0

Response Number 5
Name: Mechanix2Go
Date: July 15, 2007 at 06:19:43 Pacific
Reply:

:: find abc.dat in a tree, one level down

@echo off
setLocal EnableDelayedExpansion

pushd s:\my

for /f "tokens=* delims= " %%a in ('dir/b/ad ') do (
pushd %%a
for /f "tokens=* delims= " %%a in ('if exist abc.dat dir/b abc.dat') do (
set var=%%~DPa
)
popd
)
echo the path to abc.dat is !var!



=====================================
If at first you don't succeed, you're about average.

M2



0

Related Posts

See More



Response Number 6
Name: Alatar
Date: July 15, 2007 at 09:19:36 Pacific
Reply:

thanks a lot, it's perfect!


0

Response Number 7
Name: Alatar
Date: July 23, 2007 at 09:06:06 Pacific
Reply:

hi
i was "studying" what Mechanix2Go told me, and i was thinking if there was a particular motive to use pushd and popd in the place of cd and cd..
that is:

pushd s:\my

for /f "tokens=* delims= " %%a in ('dir/b/ad ') do (
cd %%a
for /f "tokens=* delims= " %%a in ('if exist abc.dat dir/b abc.dat') do (
set var=%%~DPa
)
cd..
)
echo the path to abc.dat is !var!


there should be any difference?
tnx


0

Response Number 8
Name: Mechanix2Go
Date: July 23, 2007 at 09:16:11 Pacific
Reply:

In this case, not much diff.


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 9
Name: Alatar
Date: July 23, 2007 at 09:39:01 Pacific
Reply:

in which case you must use pushd and popd?


0

Response Number 10
Name: Mechanix2Go
Date: July 23, 2007 at 09:49:10 Pacific
Reply:

Any time you don't want to be bothered hard coding the DIR to return to.


=====================================
If at first you don't succeed, you're about average.

M2



0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch search f. and go to that dir

Batch searching, moving and concat www.computing.net/answers/programming/batch-searching-moving-and-concat/12914.html

Batch to search and copy to new Dir www.computing.net/answers/programming/batch-to-search-and-copy-to-new-dir/16809.html

Select file and move to another pc www.computing.net/answers/programming/select-file-and-move-to-another-pc/17166.html