In acommand-line environment, auser often uses files in or relative to the working directory. The systemstate that identifies the working directory provides a convenient way to define the context of work. Users can use paths that are conceptually simpler and usually shorter, instead of always using absolute paths. For example, for working directory/home/user/data on aUnix-like system, thefile namefoo.txt (a relative path) refers to absolute path/home/user/data/foo.txt. System state for working directory often also applies in agraphical user interface (GUI), but often is not useful since the GUI environment maintains directory context in a different way.
As a feature, working directories vary by environment yet have some common, typical attributes. Typically, eachprocess has a separate working directory, which allows users to have a different working directory for eachshell running on thecomputer. Although common in systems that provide ahierarchical file system, the working directory feature is not required; for example, theDX10 operating system does not provide it, as all pathnames are either absolute or relative to the system volume.[1]
Alternate names includecurrent working directory (CWD)[b] and justcurrent directory.[3]
Manyshells provide acdcommand for setting the working directory. Some systems provide a command with a different name. For example,chdir is an alternate name forcd in DOS/Windows.
Report
Commands for reporting the working directory vary more than setting it. Typically, aUnix shell provides the commandpwd (short forprint working directory) that reports the absolute path to the working directory. The equivalent command in DOS/Windows iscd withoutarguments. Usingcd without arguments in Unix-like systems generally sets the working directory to the user'shome directory.
The working directory is displayed by the$P[nb 1] token of theDOSprompt command.[5] To keep the prompt short in a deep directory, the DR-DOS 7.07 COMMAND.COM supports a$W[nb 1] token to display only the deepest subdirectory level. So, where a defaultPROMPT $P$G would result f.e. inC:\DOS> orC:\DOS\DRDOS>, aPROMPT $N:$W$G would instead yieldC:DOS> andC:DRDOS>, respectively. A similar facility (using$W and$w) was added to4DOS as well.[4]
State for each DOS drive
Under DOS, the absolute path to the working directory for each logical volume is stored as the current directory structure (CDS). It is allocated at boot time with a slot for each logical drive (or as defined byLASTDRIVE).[6][7][8] This structure imposes a length-limit of 66 characters on the full path of each working directory, and thus implicitly also limits the maximum possible depth of subdirectories.[6]
DOS Plus and older issues of DR DOS (up toDR DOS 6.0, withBDOS 6.7 in 1991) had no such limitation[7][9][4] due to their implementations usingDOS emulation on top of aConcurrent DOS- (and thusCP/M-86-)derived kernel, which internally organized subdirectories asrelative links to parent directories instead of asabsolute paths.[7][9] SincePalmDOS (with BDOS 7.0) and DR DOS 6.0 (1992 update with BDOS 7.1) and higher switched to use a CDS formaximum compatibility with DOS programs as well, they faced the same limitations as present in other DOSes.[7][9]
ThePOSIX-defined functionchdir() (accessible viaC and the many languages that interoperate with it) is asystem call that changes the working directory.[10] Its argument is atext string that is a path to the target directory, either absolute or relative to the existing value.
Visual Basic provides the same functionality via a function with the same name.
InJava, the working directory can be obtained via thejava.nio.file.Path interface, or thejava.io.File class. The working directory cannot be changed.[11]
COMMAND.COM inDR-DOS 7.02 and higher providesECHOS, a variant of theECHO command that omits the terminating linefeed.[12][4] This can be used to create a temporary batchjob storing the working directory in an environment variable likeCD for later use. For example:
ECHOS SET CD=> SETCD.BATCHDIR >> SETCD.BATCALL SETCD.BATDEL SETCD.BAT
Alternatively, underMultiuser DOS andDR-DOS 7.02 and higher, various internal and external commands support a parameter/B (for "Batch").[13] This modifies the output of commands to become suitable for direct command-line input (when redirecting it into abatch file) or usage as a parameter for other commands (using it as input for another command). WhereCHDIR would issue a directory path likeC:\DOS, a command likeCHDIR /B would issueCHDIR C:\DOS instead, so thatCHDIR /B > RETDIR.BAT would create a temporary batchjob allowing returning to this directory later on.
^abIn the same way as$O works as alternative to$P underDR-DOSCOMMAND.COM,$W has an alias$Y except for that it gets suppressed onfloppies in order to avoidcritical error messages or delays when trying to retrieve the path of a non-inserted floppy.
^abcdPaul, Matthias R. (1997-07-30) [1994-05-01].NWDOS-TIPs — Tips & Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds. MPDOSTIP (in German) (3 ed.).Archived from the original on 2017-09-10. Retrieved2014-08-06. (NB. NWDOSTIP.TXT is a comprehensive work on Novell DOS 7 and OpenDOS 7.01, including the description of many undocumented features and internals. It is part of the author's yet largerMPDOSTIP.ZIP collection maintained up to 2001 and distributed on many sites at the time. The provided link points to a HTML-converted older version of theNWDOSTIP.TXT file.)[3]