Current drive and directory

Michael Geary Mike at DeleteThis.Geary.com
Wed May 26 18:58:02 EDT 2004


> print """MS-DOS Prompt
> 'Q' to Quit"""
>
> import os
> command = ""
>
> while command.lower() != "q":
>         directory = os.getcwd()
>         print "\n", directory, "\b>",
>         command = raw_input("\b")
>         os.system(command)

> And also, when I actually run the program, I have trouble using
> notepad on files:
>
> MS-DOS Prompt
> 'Q' to Quit
>
> C:\Documents and Settings\Erik\Desktop>cd \windows\system32
>
> C:\Documents and Settings\Erik\Desktop>notepad calc.py
>
> It opens up notepad, but syas that it can't find the file. I know it's in
> there, and I know that's the exact name.

> Ok, I guess that won't work without some complicated scripting, but
> is there a command in DOS that shows the current directory? (so i
> could just type it in when using the prompt.)

The CD command with no arguments does that. Same as pwd in Unix. In this
case, it should print the same thing as your prompt: C:\Documents and
Settings\Erik\Desktop.

BTW, you're not running MS-DOS at all. It appears that you are on Windows
2000 or XP, so when you call os.system() you are calling cmd.exe, which is a
32-bit console application, not a DOS application. And you're starting a
new, temporary instance of cmd.exe for each command, which is why your CD
command isn't having any effect.

What directory is calc.py in? \windows\system32 or your desktop? When you do
the "notepad calc.py" it is looking for calc.py in C:\Documents and
Settings\Erik\Desktop (your desktop), because that is your current
directory. If you do a File/Save... in Notepad you can confirm what Notepad
is using for the current directory.

What is it you are trying to do here? Maybe there is another way to approach
it that will work better.

-Mike





More information about the Python-list mailing list