redirection and cd/chdir?

  • Thread starter Thread starter Will
  • Start date Start date
W

Will

Trying to create a batch file to automate a program.
Learning alot about the command-line.
Now at a point where I need help.

I am able to create a text file using the folling command,

DIR /B /S VIDEO_TS > videopath

what that does, is put any full path of were a VIDEO_TS folder is to a
text file called 'videopath'

(ie, D:\RISP\GODSEND\VIDEO_TS)

the next command in the batch file I want, is to CD (CHDIR) to that
full path thats in the 'videopath' text file.

this does not work, CD %videopath% OR CD < %videopath%

Thanks,
Will
 
Will said:
Trying to create a batch file to automate a program.
Learning alot about the command-line.
Now at a point where I need help.

I am able to create a text file using the folling command,

DIR /B /S VIDEO_TS > videopath

what that does, is put any full path of were a VIDEO_TS folder is to a
text file called 'videopath'

(ie, D:\RISP\GODSEND\VIDEO_TS)

the next command in the batch file I want, is to CD (CHDIR) to that
full path thats in the 'videopath' text file.

this does not work, CD %videopath% OR CD < %videopath%

Thanks,
Will

If video_ts is a folder then the command dir /b /s video_ts > videopath
will place then ***contents*** of the video_ts folder into a text file
called videopath. This text file might now contain lots of entries such as
abc.xyz
def.qrs

If you now wish to move into the video_ts folder then you do
it with this command: cd video_ts.

I'm not sure how you came upon the idea of using the command
cd %videopath%. If you surround a string such as "videopath"
with % then you treat it as an environmental variable. Some of
these are defined by the operating system. Try this:

echo My name is %UserName%
echo This PC's name is %ComputerName%

The variable %videopath% is not a system variable. You can
define it if you wish:

set videopath=video_ts

After doing this, the following command will work:

cd %videopath%

However, there seems to be little point of doing this.

You could, of course, write the string video_ts into
a text file, then use a batch file to read the contents
of this batch file and set an environmental variable
accordingly. This goes under advanced batch
commands.
 
for /f "delims=" %A in ('dir /b /s video_TS.*') do cd %A


%%A if in a batch file, %A if typed. I presume you are using this on DVDs cause it will have unexpected resaults if used on a hard disk as it will change to ALL video directories (but there is only one on a DVD). Note no redirection or text files. We parse the Dir output direct. Type for in help for more.
 
C:\Program Files\Support Tools\video_ts>for /f "delims=" %A in ('dir /b /s vide
o_TS.*') do set videopath=%A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top