views:

73

answers:

2

I have a directory path stored in a text file, and I need to CD to that directory in a script but don't know how. I was hoping it would be something like

cat FILE | cd

but its not that easy.

This is a windows environment btw, in unix/linux it is easy:

cd `cat FILE`

Can anyone give me a hand?

+5  A: 
set /p dirname=<FILE
cd %dirname%

The documentation for set (for XP) can be found here.

/p : Sets the value of variable to a line of input.

Jared Oberhaus
Just the right hammer for the job, thank you :)
Nippysaurus
+1  A: 

In PowerShell, it is that easy:

Get-Content FILE | Set-Location

Or if you prefer the CMD aliases:

type FILE | cd

Or if you prefer the shorthand PowerShell aliases:

gc FILE | sl
Lee
I have cygwin with bash installed ... but I cant use anything like that, it needs to be pure windows stuff unfortunately.
Nippysaurus
I'm not sure what you mean by "pure windows stuff". PowerShell is written by Microsoft and is available as a free download. If you mean that it has to be a solution that is pre-installed on some version of Windows then you should probably retag your question to include "cmd" or "batch" as a tag.
Lee