Skip to content

Instantly share code, notes, and snippets.

@FGFW
Created April 7, 2016 19:10
Show Gist options
  • Select an option

  • Save FGFW/a632416cc5ac6162bdc27369c4984c68 to your computer and use it in GitHub Desktop.

Select an option

Save FGFW/a632416cc5ac6162bdc27369c4984c68 to your computer and use it in GitHub Desktop.
python判断路径是目录还是文件.py
"""
python判断路径是目录还是文件.py
http://bbs.bathome.net/thread-39957-1-1.html
2016年4月8日 03:04:00 codegay
"""
import os
files=[r for r in open("test.txt") if os.path.isfile(r.strip())]
dirs=[r for r in open("test.txt") if os.path.isdir(r.strip())]
with open("11.txt","w+") as f:
f.writelines(files)
with open("22.txt","w+") as f:
f.writelines(dirs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment