使用python搜索程序 [英] Search Program using python
本文介绍了使用python搜索程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用 python 编写一个搜索程序,它将搜索文件的文件夹作为系统参数(sys.argv).然后它会询问要查找的文件的名称.
有什么问题
1. 如何知道文件夹中有哪些文件或文件夹?是否有任何模块或功能?
I am coding a search program in python which take the folder for searching for the file as a system argument(sys.argv). It then asks for name of the file to find.
What is the problem
1. How do I know which files or folders are there in the folder? Is there any module or function for that?
推荐答案
试试这个:
import os
for item in os.listdir(path):
if not os.path.isfile(os.path.join(path, item)):
print "Folder"
else:
print "File"
这篇关于使用python搜索程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文