你好,我正在我的视图中搜索。opt.php文件编译的文件。在
目前我正在做这样的事情
for x in glob.glob(PATH_VIEWS + '*.opt.php'):
# Get file names
segment1 = x.split('/')
filename = segment1[-1]
realname = filename.split('.opt.php')
appfolder = segment1[-4]
folder = segment1[-2]
''' ../../../views/users/index.opt.php
['..', '..', '..', 'views', 'users', 'index.opt.php']
index.opt.php
['index', '']
'''
有更好的方法吗?我想
像index.opt.php
这样的文件名,本例中文件所在的文件夹位于../../../views/users
用户中
如果你想得到你可以使用的基名和目录名操作系统路径拆分():
http://docs.python.org/library/os.path.html#os.path.split
顺便说一句:glob()只在目录深度固定的情况下有效。使用手术室步行()如果您想要类似于unix“find”命令(递归目录遍历)的话。在
相关问题 更多 >
编程相关推荐