import os,sys,time
print(os.getcwd(),‘获取工作目录‘) #获取工作目录
print(os.environ[‘systemdrive‘],‘获取系统盘符‘) #获取系统盘符
print(os.environ[‘userprofile‘],‘获取用户目录‘) #获取用户目录
print(os.environ[‘windir‘],‘获取windows目录‘) #获取windows目录
for i in os.walk(‘F:\python‘,topdown=False,onerror=None): #遍历文件目录
print(i)
time.sleep(0.5);
输出结果
F:\python\zw18\毕业设计 获取工作目录
C: 获取系统盘符
C:\Users\Administrator 获取用户目录
C:\WINDOWS 获取windows目录
(‘F:\\python\\day1\\.idea‘, [], [‘day1.iml‘, ‘modules.xml‘, ‘workspace.xml‘])
(‘F:\\python\\day1‘, [‘.idea‘], [])
(‘F:\\python\\zw18\\.idea\\dictionaries‘, [], [‘Administrator.xml‘])
(‘F:\\python\\zw18\\.idea\\inspectionProfiles‘, [], [])
(‘F:\\python\\zw18\\.idea‘, [‘dictionaries‘, ‘inspectionProfiles‘], [‘encodings.xml‘, ‘misc.xml‘, ‘modules.xml‘, ‘workspace.xml‘, ‘zw18.iml‘])
(‘F:\\python\\zw18\\day1\\homework‘, [], [‘homework_1.py‘])
(‘F:\\python\\zw18\\day1\\__pycache__‘, [], [])
(‘F:\\python\\zw18\\day1‘, [‘homework‘, ‘__pycache__‘], [‘black_user.xml‘, ‘game.py‘, ‘hello.py‘, ‘homework.py‘, ‘input.py‘, ‘login.py‘])
(‘F:\\python\\zw18\\day2\\dada‘, [], [])
(‘F:\\python\\zw18\\day2\\__pycache__‘, [], [‘login.cpython-36.pyc‘])
(‘F:\\python\\zw18\\day2‘, [‘dada‘, ‘__pycache__‘], [‘login.py‘, ‘shopping.py‘, ‘time.py‘, ‘数据类型.py‘, ‘模块初识.py‘])
(‘F:\\python\\zw18\\day3‘, [], [‘进度条.py‘])
(‘F:\\python\\zw18\\Qt‘, [], [])
(‘F:\\python\\zw18\\毕业设计‘, [], [‘Qt.py‘, ‘获取内存_进程_网络.py‘, ‘遍历目录.py‘])
(‘F:\\python\\zw18‘, [‘.idea‘, ‘day1‘, ‘day2‘, ‘day3‘, ‘Qt‘, ‘毕业设计‘], [])
(‘F:\\python\\目录\\.idea\\inspectionProfiles‘, [], [])
(‘F:\\python\\目录\\.idea‘, [‘inspectionProfiles‘], [‘misc.xml‘, ‘modules.xml‘, ‘workspace.xml‘, ‘目录.iml‘])
(‘F:\\python\\目录\\venv\\Include‘, [], [])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\EGG-INFO‘, [], [‘dependency_links.txt‘, ‘entry_points.txt‘, ‘not-zip-safe‘, ‘PKG-INFO‘, ‘requires.txt‘, ‘SOURCES.txt‘, ‘top_level.txt‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\commands‘, [], [‘check.py‘, ‘completion.py‘, ‘download.py‘, ‘freeze.py‘, ‘hash.py‘, ‘help.py‘, ‘install.py‘, ‘list.py‘, ‘search.py‘, ‘show.py‘, ‘uninstall.py‘, ‘wheel.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\compat‘, [], [‘dictconfig.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\models‘, [], [‘index.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\operations‘, [], [‘check.py‘, ‘freeze.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\req‘, [], [‘req_file.py‘, ‘req_install.py‘, ‘req_set.py‘, ‘req_uninstall.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\utils‘, [], [‘appdirs.py‘, ‘build.py‘, ‘deprecation.py‘, ‘encoding.py‘, ‘filesystem.py‘, ‘glibc.py‘, ‘hashes.py‘, ‘logging.py‘, ‘outdated.py‘, ‘packaging.py‘, ‘setuptools_build.py‘, ‘ui.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\vcs‘, [], [‘bazaar.py‘, ‘git.py‘, ‘mercurial.py‘, ‘subversion.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\cachecontrol\\caches‘, [], [‘file_cache.py‘, ‘redis_cache.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\cachecontrol‘, [‘caches‘], [‘adapter.py‘, ‘cache.py‘, ‘compat.py‘, ‘controller.py‘, ‘filewrapper.py‘, ‘heuristics.py‘, ‘serialize.py‘, ‘wrapper.py‘, ‘_cmd.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\colorama‘, [], [‘ansi.py‘, ‘ansitowin32.py‘, ‘initialise.py‘, ‘win32.py‘, ‘winterm.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\distlib\\_backport‘, [], [‘misc.py‘, ‘shutil.py‘, ‘sysconfig.cfg‘, ‘sysconfig.py‘, ‘tarfile.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\distlib‘, [‘_backport‘], [‘compat.py‘, ‘database.py‘, ‘index.py‘, ‘locators.py‘, ‘manifest.py‘, ‘markers.py‘, ‘metadata.py‘, ‘resources.py‘, ‘scripts.py‘, ‘t32.exe‘, ‘t64.exe‘, ‘util.py‘, ‘version.py‘, ‘w32.exe‘, ‘w64.exe‘, ‘wheel.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib\\filters‘, [], [‘alphabeticalattributes.py‘, ‘base.py‘, ‘inject_meta_charset.py‘, ‘lint.py‘, ‘optionaltags.py‘, ‘sanitizer.py‘, ‘whitespace.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib\\treeadapters‘, [], [‘genshi.py‘, ‘sax.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib\\treebuilders‘, [], [‘base.py‘, ‘dom.py‘, ‘etree.py‘, ‘etree_lxml.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib\\treewalkers‘, [], [‘base.py‘, ‘dom.py‘, ‘etree.py‘, ‘etree_lxml.py‘, ‘genshi.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib\\_trie‘, [], [‘datrie.py‘, ‘py.py‘, ‘_base.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib‘, [‘filters‘, ‘treeadapters‘, ‘treebuilders‘, ‘treewalkers‘, ‘_trie‘], [‘constants.py‘, ‘html5parser.py‘, ‘serializer.py‘, ‘_ihatexml.py‘, ‘_inputstream.py‘, ‘_tokenizer.py‘, ‘_utils.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\lockfile‘, [], [‘linklockfile.py‘, ‘mkdirlockfile.py‘, ‘pidlockfile.py‘, ‘sqlitelockfile.py‘, ‘symlinklockfile.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\packaging‘, [], [‘markers.py‘, ‘requirements.py‘, ‘specifiers.py‘, ‘utils.py‘, ‘version.py‘, ‘_compat.py‘, ‘_structures.py‘, ‘__about__.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\pkg_resources‘, [], [‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\progress‘, [], [‘bar.py‘, ‘counter.py‘, ‘helpers.py‘, ‘spinner.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\chardet‘, [], [‘big5freq.py‘, ‘big5prober.py‘, ‘chardetect.py‘, ‘chardistribution.py‘, ‘charsetgroupprober.py‘, ‘charsetprober.py‘, ‘codingstatemachine.py‘, ‘compat.py‘, ‘constants.py‘, ‘cp949prober.py‘, ‘escprober.py‘, ‘escsm.py‘, ‘eucjpprober.py‘, ‘euckrfreq.py‘, ‘euckrprober.py‘, ‘euctwfreq.py‘, ‘euctwprober.py‘, ‘gb2312freq.py‘, ‘gb2312prober.py‘, ‘hebrewprober.py‘, ‘jisfreq.py‘, ‘jpcntx.py‘, ‘langbulgarianmodel.py‘, ‘langcyrillicmodel.py‘, ‘langgreekmodel.py‘, ‘langhebrewmodel.py‘, ‘langhungarianmodel.py‘, ‘langthaimodel.py‘, ‘latin1prober.py‘, ‘mbcharsetprober.py‘, ‘mbcsgroupprober.py‘, ‘mbcssm.py‘, ‘sbcharsetprober.py‘, ‘sbcsgroupprober.py‘, ‘sjisprober.py‘, ‘universaldetector.py‘, ‘utf8prober.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\urllib3\\contrib‘, [], [‘appengine.py‘, ‘ntlmpool.py‘, ‘pyopenssl.py‘, ‘socks.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\urllib3\\packages\\ssl_match_hostname‘, [], [‘_implementation.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\urllib3\\packages‘, [‘ssl_match_hostname‘], [‘ordered_dict.py‘, ‘six.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\urllib3\\util‘, [], [‘connection.py‘, ‘request.py‘, ‘response.py‘, ‘retry.py‘, ‘ssl_.py‘, ‘timeout.py‘, ‘url.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\urllib3‘, [‘contrib‘, ‘packages‘, ‘util‘], [‘connection.py‘, ‘connectionpool.py‘, ‘exceptions.py‘, ‘fields.py‘, ‘filepost.py‘, ‘poolmanager.py‘, ‘request.py‘, ‘response.py‘, ‘_collections.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages‘, [‘chardet‘, ‘urllib3‘], [‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests‘, [‘packages‘], [‘adapters.py‘, ‘api.py‘, ‘auth.py‘, ‘cacert.pem‘, ‘certs.py‘, ‘compat.py‘, ‘cookies.py‘, ‘exceptions.py‘, ‘hooks.py‘, ‘models.py‘, ‘sessions.py‘, ‘status_codes.py‘, ‘structures.py‘, ‘utils.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\webencodings‘, [], [‘labels.py‘, ‘mklabels.py‘, ‘tests.py‘, ‘x_user_defined.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor‘, [‘cachecontrol‘, ‘colorama‘, ‘distlib‘, ‘html5lib‘, ‘lockfile‘, ‘packaging‘, ‘pkg_resources‘, ‘progress‘, ‘requests‘, ‘webencodings‘], [‘appdirs.py‘, ‘distro.py‘, ‘ipaddress.py‘, ‘ordereddict.py‘, ‘pyparsing.py‘, ‘re-vendor.py‘, ‘retrying.py‘, ‘six.py‘, ‘__init__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip‘, [‘commands‘, ‘compat‘, ‘models‘, ‘operations‘, ‘req‘, ‘utils‘, ‘vcs‘, ‘_vendor‘], [‘basecommand.py‘, ‘baseparser.py‘, ‘cmdoptions.py‘, ‘download.py‘, ‘exceptions.py‘, ‘index.py‘, ‘locations.py‘, ‘pep425tags.py‘, ‘status_codes.py‘, ‘wheel.py‘, ‘__init__.py‘, ‘__main__.py‘])
(‘F:\\python\\目录\\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg‘, [‘EGG-INFO‘, ‘pip‘], [])
(‘F:\\python\\目录\\venv\\Lib\\site-packages‘, [‘pip-9.0.1-py3.6.egg‘], [‘easy-install.pth‘, ‘setuptools-28.8.0-py3.6.egg‘, ‘setuptools.pth‘])
(‘F:\\python\\目录\\venv\\Lib\\tcl8.6‘, [], [‘init.tcl‘])
(‘F:\\python\\目录\\venv\\Lib‘, [‘site-packages‘, ‘tcl8.6‘], [])
(‘F:\\python\\目录\\venv\\Scripts‘, [], [‘activate‘, ‘activate.bat‘, ‘Activate.ps1‘, ‘deactivate.bat‘, ‘easy_install-3.6-script.py‘, ‘easy_install-3.6.exe‘, ‘easy_install-3.6.exe.manifest‘, ‘easy_install-script.py‘, ‘easy_install.exe‘, ‘easy_install.exe.manifest‘, ‘pip-script.py‘, ‘pip.exe‘, ‘pip.exe.manifest‘, ‘pip3-script.py‘, ‘pip3.6-script.py‘, ‘pip3.6.exe‘, ‘pip3.6.exe.manifest‘, ‘pip3.exe‘, ‘pip3.exe.manifest‘, ‘pyexpat.pyd‘, ‘python.exe‘, ‘python3.dll‘, ‘python36.dll‘, ‘pythonw.exe‘, ‘select.pyd‘, ‘sqlite3.dll‘, ‘tcl86t.dll‘, ‘tk86t.dll‘, ‘unicodedata.pyd‘, ‘vcruntime140.dll‘, ‘winsound.pyd‘, ‘_asyncio.pyd‘, ‘_bz2.pyd‘, ‘_ctypes.pyd‘, ‘_ctypes_test.pyd‘, ‘_decimal.pyd‘, ‘_elementtree.pyd‘, ‘_hashlib.pyd‘, ‘_lzma.pyd‘, ‘_msi.pyd‘, ‘_multiprocessing.pyd‘, ‘_overlapped.pyd‘, ‘_socket.pyd‘, ‘_sqlite3.pyd‘, ‘_ssl.pyd‘, ‘_testbuffer.pyd‘, ‘_testcapi.pyd‘, ‘_testconsole.pyd‘, ‘_testimportmultiple.pyd‘, ‘_testmultiphase.pyd‘, ‘_tkinter.pyd‘])
(‘F:\\python\\目录\\venv‘, [‘Include‘, ‘Lib‘, ‘Scripts‘], [‘pyvenv.cfg‘])
(‘F:\\python\\目录‘, [‘.idea‘, ‘venv‘], [])
(‘F:\\python‘, [‘day1‘, ‘zw18‘, ‘目录‘], [])