batch script to find the path of file and set

November 19, 2010 at 02:39:12
Specs: Windows 7, 2gb
Hi All,

How can i find the path / folder in which example .txt recieds through batch script.

i have file at some folder i need to get the path and set that in one variable eg: %2 so that i can pass that variable %2

Thanks


See More: batch script to find the path of file and set

Report •


#1
November 19, 2010 at 09:03:23

for /f %2 in ('dir /s /b yourfilename.txt') do (echo %2)

In above example the, it will find your filename and set the variable %2 with the path. In last i used echo %2, so it will echo the same on the screen as well..
Now you can do anything you want with the variable %2 .

Subhash Chandra.


Report •

#2
November 19, 2010 at 09:52:04
%2 is a terrible variable; it's already in use.

How To Ask Questions The Smart Way


Report •

#3
November 19, 2010 at 11:21:26
the questioner used %2 in his question thats why i used the same thing here so it will be conveient for him to understand the flow.

I agree that %1 %2 %3 .... are the variables which are already used by DOS to denote parameters passed to the batch.

Subhash Chandra.


Report •

Related Solutions


Ask Question