Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I receive a file that contains the following:
\direcotry1\directory2\directory3\file1
\direcotry1\file2
\direcotry1\directory2\directory3\directory4\file3 \direcotry1\file4
\direcotry1\directory2\file5
file6The amount of files in the file and the amount of directories are variable.
What I need is the path only.
\direcotry1\directory2\directory3\ for file1 \direcotry1\ for file2
\direcotry1\directory2\directory3\directory4\ for file3 \direcotry1\ for file4
\direcotry1\directory2\ for file5
and nothing for file6I used the variable %%~pi which works for all except for the last one. For the last one it returns \cft\
I guess the \cft\ is returned as the program that is calling the bat file launches it from there.FOR /F %%i in (test.txt) DO (
echo %%~pi
command1
command2
)Does anyone know how I can avoid that the batfile returns \cft\? I want the bat to return nothing when there's no path.
Thanks a lot in advance for your help.

using find:
C:\batch>for /f "tokens=*" %a in (test.txt) do @echo %~pa|find /v "%cd:~2%\" \direcotry1\directory2\directory3\ \direcotry1\ \direcotry1\directory2\directory3\directory4\ \direcotry1\directory2\
using if:C:\batch>for /f "tokens=*" %a in (test.txt) do @if not .%~pa==.%cd:~2%\ echo %~pa \direcotry1\directory2\directory3\ \direcotry1\ \direcotry1\directory2\directory3\directory4\ \direcotry1\directory2\

![]() |
![]() |
![]() |

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