Solved batch script to find the directory of a file

July 16, 2011 at 12:51:14
Specs: Windows 7
could someone please write a batch script for me that does the following work:

1. takes a file as an argument
2. stores the file's directory in a variable

eg. input:
bfile "C:\hello\hi\tada.txt"

output(should be saved in a variable):
C:\hello\hi

please help.


See More: batch script to find the directory of a file

Report •


#1
July 16, 2011 at 15:47:43
✔ Best Answer
Hi Divs1210

You only need to use this syntax
BatchFileName tada.txt with or without quotes

@echo off
cd\
for /f "tokens=* delims=" %%a in ('dir /s/b ^| find "%~1"') do (
set Found=%%~da%%~pa
)
echo Found=%Found%


Report •

#2
July 17, 2011 at 14:50:31
hey! thanks a LOT for this!
was frustrating me for some time! kudos!

Report •

Related Solutions


Ask Question