You try to redirect the contents of a file named type
to the cd
command. The correct syntax would be cd < path.txt
or type path.txt | cd
- if cd
would take input from STDIN, which it does not.
You have to read the content of path.txt
to a variable and use cd
with that variable.
There are two methods to read from a file: set /p
and a for /f
loop.
A
<path.txt set /p folder=
cd /d "%folder%"
or B
for /f "usebackq delims=" %%a in ("path.txt") do set folder=%%a
cd /d "%folder%"
or (directly processing) C
for /f "usebackq delims=" %%a in ("path.txt") do cd /d "%%a"
(All methods assuming there is just one line in the file - method A reads the first line only, method B reads all (non-empty) lines, keeping the last one in the variable and method C would cd
in every folder listed in the file.)