Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
I was just trying to set a variable to the contents of a file in a batch file. For example... I did a CD>Current_dir.txt to find out where I am.. and then want to set a CRNT_DIR=current_dir.txt... but can't figure out the syntax.
Any thoughts? Would be greatly appreciated.
Or a better way to get the current dir in a batch file.. so I can copy some files to it.
~Bob

The following sample batch guides you to the solution; anyway there are other ways to fit your need.
@Echo Off
:: XCD.BAT Syntax: XCD , batch to store the
:: current directory into a variableFor /F "tokens=*" %%A in ('CD') Do Set Crnt_Dir=%%A
Echo.
Echo The current directory is %Crnt_Dir%Good work.

However, if you just want to copy files to the current directory, use the following syntax:
copy c:\path\file.ext file.ext
Or this one:
copy c:\path\file.ext .
The dot (.) on the begin of a filename's path stands for the current directory (doesn't mean it will be expanded to the CD's name, a command like "echo ." won't display the current directory.
Now, if you'll be changing the directory and need the original CD on a variable, you'd better use IVO's method. On NT5+ (Win 2K/XP), the dynamic variable %CD% carries the CD by default. But I reckon on NT4- it's different. So, on NT5+, all you gotta do is:
set ORIGINAL_CD=%CD%
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

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

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