|
Answer» I'm sure this has been asked a thousand times, but I've looked on Google and the forums: How do I set the current directory as a variable?set = I believe you've mentioned that you run XP. %cd% will work equally well.
8-)Using cmd.exe within XP, %CD% returns the current directory string variable:
%ALLUSERSPROFILE% Local - Returns the location of the All Users Profile.
%APPDATA% Local - Returns the location where applications store data by default.
%CD% Local - Returns the current directory string.
%CMDCMDLINE% Local - Returns the exact command line used to start the current Cmd.exe.
%CMDEXTVERSION% System - Returns the VERSION number of the current Command Processor Extensions.
%COMPUTERNAME% System - Returns the name of the computer.
%COMSPEC% System - Returns the exact path to the command shell executable.
%DATE% System - Returns the current date. Uses the same format as the date /t command. Generated by Cmd.exe. For more information about the date command, see Date
%ERRORLEVEL% System - Returns the error code of the most recently used command. A non zero value usually indicates an error.
%HOMEDRIVE% System - Returns which local workstation drive letter is connected to the user's home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
%HOMEPATH% System - Returns the full path of the user's home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
%HOMESHARE% System - Returns the network path to the user's shared home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
%LOGONSEVER% Local - Returns the name of the domain controller that validated the current logon session.
%NUMBER_OF_PROCESSORS% System - Specifies the number of processors installed on the computer.
%OS% System - Returns the operating system name. Windows 2000 displays the operating system as Windows_NT.
%PATH% System - Specifies the search path for executable files.
%PATHEXT% System - Returns a list of the file extensions that the operating system considers to be executable.
%PROCESSOR_ARCHITECTURE% System - Returns the chip architecture of the processor. Values: x86, IA64.
%PROCESSOR_IDENTIFIER% System Returns a description of the processor.
%PROCESSOR_LEVEL% System - Returns the model number of the processor installed on the computer.
%PROCESSOR_REVISION% System - Returns the revision number of the processor.
%PROMPT% Local - Returns the command prompt settings for the current interpreter. Generated by Cmd.exe.
%RANDOM% System - Returns a random DECIMAL number between 0 and 32767. Generated by Cmd.exe.
%SYSTEMDRIVE% System - Returns the drive containing the Windows XP root directory (that is, the system root).
%SYSTEMROOT% System - Returns the location of the Windows XP root directory.
%TEMP% and %TMP% System and User - Returns the default temporary directories that are used by applications available to users who are currently logged on. Some applications require TEMP and others require TMP.
%TIME% System - Returns the current time. Uses the same format as the time /t command. Generated by Cmd.exe. For more information about the time command, see Time
%USERDOMAIN% Local - Returns the name of the domain that contains the user's account.
%USERNAME% Local - Returns the name of the user who is currently logged on.
%USERPROFILE% Local - Returns the location of the profile for the current user.
%WINDIR% System - Returns the location of the operating system directory.Typing %CD% gives me basically a Bad Command or File Name error.
/me forgot the ECHO... fixed now...
Instead of just making ANOTHER thread, I'll ask it here: How do I stop the thing from changing to 8.3 format? It made the current directory variable C:\Utilit~1, when it should be C:\Utilities.
My simple code for TEST.BAT was:
Code: [Select]@ECHO OFF
SET currdir=%cd% ECHO The current directory is: PAUSE cls ECHO %currdir% And currdir became C:\Utilit~1. This is a bad thing if I want to return the user to their previous directory. It does this every time I edit a BAT file or something like that.If it helps...
Off the top of my head, and it's Saturday evening so I'm probably completely wrong, use the /k switch to launch cmd.exe: cmd.exe /k Try cmd /? in a command WINDOW to check.Not sure I understand the problem. When I ran your batch file, I was able to use a long directory name without a conversion to a short name.
In any case, is not c:\utilit~1 equivalent to c:\utitlities? The OS seems to think so.
8-)Hmm. It's working now. Odd. Last time I put in that ~ it gave me a error... must have spelled it wrong.
/me bangs head slowly on computer
And it never goes to 8.3 when running a batch file - just when editing it.Dilbert,
Seems that the edit.com program is old DOS school and changes the shell format to 8.3. The script content itself is innocent. If it bothers you then use notepad instead or even BETTER download one of the cool free editors like Crimpson from http://www.crimsoneditor.com.
|