Working directory

Last updated

In computing, the working directory of a process is a directory of a hierarchical file system, if any, [nb 1] dynamically associated with the process. It is sometimes called the current working directory (CWD), e.g. the BSD getcwd [1] function, or just current directory. [2] When a process refers to a file using a simple file name or relative path (as opposed to a file designated by a full path from a root directory), the reference is interpreted relative to the working directory of the process. So for example a process with working directory /rabbit-shoes that asks to create the file foo.txt will end up creating the file /rabbit-shoes/foo.txt.

Contents

In operating systems

In most computer file systems, every directory has an entry (usually named ".") which points to the directory itself.

In most DOS and UNIX command shells, as well as in the Microsoft Windows command line interpreters cmd.exe and Windows PowerShell, the working directory can be changed by using the CD or CHDIR commands. In Unix shells, the pwd command outputs a full pathname of the working directory; the equivalent command in DOS and Windows is CD or CHDIR without arguments (whereas in Unix, cd used without arguments takes the user back to their home directory).

The environment variable PWD (in Unix/Linux shells), or the pseudo-environment variables CD (in Windows COMMAND.COM and cmd.exe, but not in OS/2 and DOS), or _CWD, _CWDS, _CWP and _CWPS (under 4DOS, 4OS2, 4NT etc.) [3] can be used in scripts, so that one need not start an external program. Microsoft Windows file shortcuts have the ability to store the working directory.

COMMAND.COM in DR-DOS 7.02 and higher provides ECHOS, a variant of the ECHO command omitting the terminating linefeed. [4] [3] This can be used to create a temporary batchjob storing the working directory in an environment variable like CD for later use, for example:

ECHOS SET CD=> SETCD.BAT CHDIR >> SETCD.BAT CALL SETCD.BAT DEL SETCD.BAT

Alternatively, under Multiuser DOS and DR-DOS 7.02 and higher, various internal and external commands support a parameter /B (for "Batch"). [5] This modifies the output of commands to become suitable for direct command line input (when redirecting it into a batch file) or usage as a parameter for other commands (using it as input for another command). Where CHDIR would issue a directory path like C:\DOS, a command like CHDIR /B would issue CHDIR C:\DOS instead, so that CHDIR /B > RETDIR.BAT would create a temporary batchjob allowing to return to this directory later on.

The working directory is also displayed by the $P [nb 2] token of the PROMPT command [6] To keep the prompt short even inside of deep subdirectory structures, the DR-DOS 7.07 COMMAND.COM supports a $W [nb 2] token to display only the deepest subdirectory level. So, where a default PROMPT $P$G would result f.e. in C:\DOS> or C:\DOS\DRDOS>, a PROMPT $N:$W$G would instead yield C:DOS> and C:DRDOS>, respectively. A similar facility (using $W and $w) was added to 4DOS as well. [3]

Under DOS, the absolute paths of the working directories of all logical volumes are internally stored in an array-like data structure called the Current Directory Structure (CDS), which gets dynamically allocated at boot time to hold the necessary number of slots for all logical drives (or as defined by LASTDRIVE). [7] [8] [9] 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. [7] DOS Plus and older issues of DR DOS (up to DR DOS 6.0, with BDOS 6.7 in 1991) had no such limitation [8] [10] [3] due to their implementation using a DOS emulation on top of a Concurrent DOS- (and thus CP/M-86-)derived kernel, which internally organized subdirectories as relative links to parent directories instead of as absolute paths. [8] [10] Since PalmDOS (with BDOS 7.0) and DR DOS 6.0 (1992 update with BDOS 7.1) and higher switched to use a CDS for maximum compatibility with DOS programs as well, they faced the same limitations as present in other DOSes. [8] [10]

In programming languages

Most programming languages provide an interface to the file system functions of the operating system, including the ability to set (change) the working directory of the program.

In the C language, the POSIX function chdir() effects the system call which changes the working directory. [11] Its argument is a text string with a path to the new directory, either absolute or relative to the old one. Where available, it can be called by a process to set its working directory.

There are similar functions in other languages. For example, in Visual Basic it is usually spelled CHDIR().

Unlike the Windows API or POSIX C function, neither the Java programming language nor the Java Virtual Machine supports chdir() directly;[ clarification needed ] a change request remained open for over a decade while the team responsible for Java considered the alternatives, though by 2008 the request was denied after only limited support was introduced (affecting first java.lang.Runtime and later, java.lang.ProcessBuilder ). [12]

See also

Notes

  1. There are operating systems that support a hierarchical file system but have no concept of "working directory"; for example Texas Instruments' DX10, used for the TI-990 series.
  2. 1 2 In the same way as $O works as alternative to $P under DR-DOS COMMAND.COM, $W has an alias $Y except for that it gets suppressed on floppies in order to avoid critical error messages or delays when trying to retrieve the path of a non-inserted floppy.

Related Research Articles

<span class="mw-page-title-main">Drive letter assignment</span> Alphabetical assignment to logical drives on computers (e.g., C:\)

In computer data storage, drive letter assignment is the process of assigning alphabetical identifiers to volumes. Unlike the concept of UNIX mount points, where volumes are named and located arbitrarily in a single hierarchical namespace, drive letter assignment allows multiple highest-level namespaces. Drive letter assignment is thus a process of using letters to name the roots of the "forest" representing the file system; each volume holds an independent "tree".

<span class="mw-page-title-main">DR-DOS</span> MS-DOS-like operating system

DR-DOS is a disk operating system for IBM PC compatibles. Upon its introduction in 1988, it was the first DOS that attempted to be compatible with IBM PC DOS and MS-DOS.

<span class="mw-page-title-main">COMMAND.COM</span> Default command line for MS-DOS and Windows 9x

COMMAND.COM is the default command-line interpreter for MS-DOS, Windows 95, Windows 98 and Windows Me. In the case of DOS, it is the default user interface as well. It has an additional role as the usual first program run after boot, hence being responsible for setting up the system by running the AUTOEXEC.BAT configuration file, and being the ancestor of all processes.

cd (command) Computer command in various operating systems

The cd command, also known as chdir, is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.

In computing, a command is a directive to a computer program to perform a specific task. It may be issued via a command-line interface or as input to a network service as part of a network protocol, or as an event triggered in a graphical user interface.

<span class="mw-page-title-main">4DOS</span> Command line interpreter

4DOS is a command-line interpreter by JP Software, designed to replace the default command interpreter COMMAND.COM in Microsoft DOS and Windows. It was written by Rex C. Conn and Tom Rawson and first released in 1989. Compared to the default, it has a large number of enhancements.

An environment variable is a user-definable value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.

A path is a string of characters used to uniquely identify a location in a directory structure. It is composed by following the directory tree hierarchy in which components, separated by a delimiting character, represent each directory. The delimiting character is most commonly the slash ("/"), the backslash character ("\"), or colon (":"), though some operating systems may use a different delimiter. Paths are used extensively in computer science to represent the directory/file relationships common in modern operating systems and are essential in the construction of Uniform Resource Locators (URLs). Resources can be represented by either absolute or relative paths.

<span class="mw-page-title-main">DOSKEY</span>

DOSKEY is a command for DOS, IBM OS/2, Microsoft Windows, and ReactOS that adds command history, macro functionality, and improved editing features to the command-line interpreters COMMAND.COM and cmd.exe.

AUTOEXEC.BAT is a system file that was originally on DOS-type operating systems. It is a plain-text batch file in the root directory of the boot device. The name of the file is an abbreviation of "automatic execution", which describes its function in automatically executing commands on system startup; the filename was coined in response to the 8.3 filename limitations of the FAT file system family.

In computing, the exit status, or exit code, of a terminated process is an integer number that is made available to its parent process. In DOS, this may be referred to as an errorlevel.

<span class="mw-page-title-main">ViewMAX</span> File manager

ViewMAX is a CUA-compliant file manager supplied with DR DOS versions 5.0 and 6.0. It is based on a cut-down runtime version of Digital Research's GEM/3 graphical user interface modified to run only a single statically built application, the ViewMAX desktop. Support for some unneeded functions has been removed whilst some new functions were added at the same time. Nevertheless, the systems remained close enough for ViewMAX to recognize GEM desktop accessories automatically and to allow some native GEM applications to be run inside the ViewMAX environment. Many display drivers for GEM 3.xx could be used by ViewMAX as well, enabling ViewMAX to be used with non-standard display adapters and higher resolutions than possible using the default set of ViewMAX drivers. Also, Digital Research's SID86, the symbolic instruction debugger that shipped with DR DOS 3.xx and provided dedicated functions to debug GEM applications, could be used for ViewMAX as well.

<span class="mw-page-title-main">Comparison of command shells</span>

A command shell is a command-line interface to interact with and manipulate a computer's operating system.

<span class="mw-page-title-main">DOS Plus</span> Discontinued computer operating system for x86 processors

DOS Plus was the first operating system developed by Digital Research's OEM Support Group in Newbury, Berkshire, UK, first released in 1985. DOS Plus 1.0 was based on CP/M-86 Plus combined with the PCMODE emulator from Concurrent PC DOS 4.11. While CP/M-86 Plus and Concurrent DOS 4.1 still had been developed in the United States, Concurrent PC DOS 4.11 was an internationalized and bug-fixed version brought forward by Digital Research UK. Later DOS Plus 2.x issues were based on Concurrent PC DOS 5.0 instead. In the broader picture, DOS Plus can be seen as an intermediate step between Concurrent CP/M-86 and DR DOS.

Long filename (LFN) support is Microsoft's backward-compatible extension of the 8.3 filename naming scheme used in DOS. Long filenames can be more descriptive, including longer filename extensions such as .jpeg, .tiff, .html, and .xhtml that are common on other operating systems, rather than specialized shortened names such as .jpg, .tif, .htm, or .xht. The standard has been common with File Allocation Table (FAT) filesystems since its first implementation in Windows NT 3.5 of 1994.

<span class="mw-page-title-main">Debug (command)</span> Line-oriented debug utility in DOS

The line-oriented debugger DEBUG.EXE is an external command in operating systems such as DOS, OS/2 and Windows.

A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. A batch file may contain any command the interpreter accepts interactively and use constructs that enable conditional branching and looping within the batch file, such as IF, FOR, and GOTO labels. The term "batch" is from batch processing, meaning "non-interactive execution", though a batch file might not process a batch of multiple data.

In computing, pushd and popd are a pair of commands which allow users to quickly switch between the current and previous directory when using the command line. When called, they use a directory stack to sequentially save and retrieve directories visited by the user.

<span class="mw-page-title-main">Command-line interface</span> Computer interface that uses text

A command-line interface (CLI) is a means of interacting with a computer program by inputting lines of text called command-lines. Command-line interfaces emerged in the mid-1960s, on computer terminals, as a user-friendly alternative to punched cards.

References

  1. getcwd(3)
  2. "Microsoft Windows – SetCurrentDirectory function". Microsoft. Archived from the original on 2018-05-27. Retrieved 2017-05-27.
  3. 1 2 3 4 Brothers, Hardin; Rawson, Tom; Conn, Rex C.; Paul, Matthias R.; Dye, Charles E.; Georgiev, Luchezar I. (2002-02-27). 4DOS 8.00 online help.
  4. DR-DOS 7.03 WHATSNEW.TXT — Changes from DR-DOS 7.02 to DR-DOS 7.03. Caldera, Inc. 1998-12-24. Archived from the original on 2019-04-08. Retrieved 2019-04-08.
  5. CCI Multiuser DOS 7.22 GOLD Online Documentation. Concurrent Controls, Inc. (CCI). 1997-02-10. HELP.HLP.
  6. Caldera DR-DOS 7.02 User Guide. Caldera, Inc. 1998 [1993, 1997]. Archived from the original on 2016-11-04. Retrieved 2013-08-10.
  7. 1 2 Schulman, Andrew; Brown, Ralf D.; Maxey, David; Michels, Raymond J.; Kyle, Jim (1994) [November 1993]. Undocumented DOS: A programmer's guide to reserved MS-DOS functions and data structures - expanded to include MS-DOS 6, Novell DOS and Windows 3.1 (2 ed.). Reading, Massachusetts: Addison Wesley. ISBN   0-201-63287-X. ISBN   978-0-201-63287-3. (xviii+856+vi pages, 3.5-inch floppy) Errata:
  8. 1 2 3 4 Paul, 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. Retrieved 2014-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 larger MPDOSTIP.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 the NWDOSTIP.TXT file.)
  9. Brown, Ralf D.; et al., eds. (2000-07-16). "Ralf Brown's Interrupt List" (61 ed.). INTER61.
  10. 1 2 3 Paul, Matthias R. (1997-06-07) [April 1994]. "Chapter 1.3.xi: Überlange Pfade". NWDOS7UN.TXT — Zusammenfassung der dokumentierten und undokumentierten Fähigkeiten von Novell DOS 7. MPDOSTIP (in German). Archived from the original on 2016-11-07. Retrieved 2016-11-07.
  11. "The Open Group Base Specifications Issue 6 and IEEE Std 1003.1" (Issue 6, 2004 ed.). The IEEE and The Open Group. 2004 [2001]. Archived from the original on 2018-02-09. Retrieved 2018-05-27.
  12. "JDK-4045688: Add chdir or equivalent notion of changing working directory". Bug Database. Oracle (Sun Microsystems). 2008-08-18 [1997-04-17]. Archived from the original on 2017-10-19. Retrieved 2011-02-20.

Further reading