windows - In a batch file, how would I find the specific folder it is in without the rest of its directory? -
okay, want batch file detect whether if can find file inhabiting , not else.
for example: receive path, (down there) variable %~dp1.
c:\users\%username%\desktop\file\file1.bat
but want receive section of directory, "\file\", , check whether batch file can find out if directory exists.
here solution, did not code solution file being in root.
variable f believe asking for.
foo.cmd
@echo off setlocal ::: p parent ::: g grandparent ::: grandparent absolute ::: f folder of batch file set p=%~dp0 set g=%~dp0\.. /f "delims=" %%t in ("%g%") set "a=%%~ft" call set f=%%p:%a%=%% call set f=%%f:\=%% echo p is: %p% echo g is: %g% echo is: %a% echo f is: %f% endlocal test cases
l:\test>foo.cmd p is: l:\test\ g is: l:\test\\.. is: l:\ f is: test l:\test>md subdir l:\test>cd subdir l:\test\subdir>..\foo.cmd p is: l:\test\ g is: l:\test\\.. is: l:\ f is: test l:\test\subdir>copy ..\foo.cmd 1 file(s) copied. l:\test\subdir>foo.cmd p is: l:\test\subdir\ g is: l:\test\subdir\\.. is: l:\test f is: subdir l:\test\subdir>cd.. l:\test>cd.. l:\>copy test\foo.cmd 1 file(s) copied. l:\>foo.cmd p is: l:\ g is: l:\\.. is: l:\ f is: \=
Comments
Post a Comment