Search code examples
windows-xpdirectorywildcardcd

Why does cd sometimes fail when expanding a wildcard


Windows XP cmd session

Why does cd P* fail with the message "The process cannot access the file because it is being used by another process." ? cd Pr* works as expected.

C:\>dir
 Volume in drive C has no label.
 Volume Serial Number is C8D7-D7A3

 Directory of C:\

01/09/2012  10:52 AM               483 aclient.cfg
08/18/2011  03:04 PM                 0 AUTOEXEC.BAT
08/18/2011  03:04 PM                 0 CONFIG.SYS
01/13/2012  01:09 PM    <DIR>          cygwin
08/18/2011  03:16 PM    <DIR>          dell
01/11/2012  10:53 AM    <DIR>          Documents and Settings
08/18/2011  03:19 PM    <DIR>          Intel
08/19/2011  10:18 AM    <DIR>          oracle
03/26/2012  02:09 PM    <DIR>          Program Files
03/29/2012  02:53 PM    <DIR>          Quarantine
03/29/2012  03:43 PM    <DIR>          WINDOWS
               3 File(s)            483 bytes
               8 Dir(s)  233,362,567,168 bytes free

C:\>cd P*
The process cannot access the file because it is being used by another process.

C:\>cd Pr*

C:\Program Files>

Solution

  • A dir /a will reveal a pagefile.sys which would account for a conflict between what you think you're doing, and what the shell is attempting to do. The shell will evaluate the first thing named, starting with a p and try to change directory into it (even if it isn't a directory).