Python os.system('dir')指向'C:\'而不是'C:\ myfolder \'。任何想法为什么以及如何解决它? 环境:Windows 7,Python3.4
答案 0 :(得分:1)
请检查这是否适合您。
import os
#Will print current working directory content
#That will be where the script is present
os.system("dir")
print "---------------------------------"
#Will print content of C:\Python27
os.system("dir C:\Python27")
输出
C:\Users\Administrator\Desktop>python chk.py
Volume in drive C has no label.
Volume Serial Number is 2A3D-7B34
Directory of C:\Users\Administrator\Desktop
08/28/2015 01:56 PM <DIR> .
08/28/2015 01:56 PM <DIR> ..
08/19/2015 02:27 PM 27,156,654 a.bmp
08/31/2015 11:33 AM 187 chk.py
08/28/2015 11:20 AM 234 data.txt
08/13/2015 04:07 PM 502 eclipse - Shor
08/13/2015 03:39 PM 502 eclipse - Shor
06/24/2015 05:28 PM 876,888 freeSSHd.exe
08/27/2015 11:45 PM 970 FreeSSHd.lnk
05/27/2014 08:54 AM 1,073 Notepad++.lnk
05/21/2014 09:59 AM 1,892 P4V.lnk
05/20/2014 12:39 PM 520,192 putty.exe
08/28/2015 01:55 PM 567,978 sample.txt
11 File(s) 29,127,072 bytes
2 Dir(s) 15,955,296,256 bytes free
---------------------------------
Volume in drive C has no label.
Volume Serial Number is 2A3D-7B34
Directory of C:\Python27
05/20/2014 08:00 PM <DIR> .
05/20/2014 08:00 PM <DIR> ..
05/20/2014 08:00 PM <DIR> DLLs
05/20/2014 08:00 PM <DIR> Doc
05/20/2014 08:00 PM <DIR> include
08/28/2015 10:20 AM <DIR> Lib
05/20/2014 08:00 PM <DIR> libs
11/10/2013 07:28 PM 38,573 LICENSE.txt
11/10/2013 11:15 AM 375,685 NEWS.txt
11/10/2013 07:24 PM 27,136 python.exe
11/10/2013 07:24 PM 27,648 pythonw.exe
10/27/2013 05:01 PM 55,208 README.txt
05/20/2014 08:00 PM <DIR> tcl
05/20/2014 08:00 PM <DIR> Tools
5 File(s) 524,250 bytes
9 Dir(s) 15,955,296,256 bytes free