一个关于判断文件夹或文件名是否有空格的小脚本,没啥大作用,自己练习瞎写的。
不过涉及到的知识点还挺多。
cat check_filename.py
#!/usr/bin/python
import os, sys
res_dir = os.listdir("/var/www/html")
for res_list in range(len(res_dir)):
print res_list,".",res_dir[res_list]
dir_num = raw_input("Please Input project number:")
def func(x):
try:
x=int(x)
return isinstance(x,int)
except ValueError:
print "input type is error!!!"
sys.exit()
func(dir_num)
if int(dir_num) >= len(res_dir) or int(dir_num) < 0:
print "input number is error!!!"
sys.exit()
dir_path = "/var/www/html/" + res_dir[int(dir_num)]
file_name_list = []
file_path_list = []
for root, dirs, files in os.walk(dir_path):
for file_list in files:
if " " in file_list:
file_name_list.append(os.path.join(root,file_list))
for dir_list in dirs:
if " " in dir_list:
file_path_list.append(os.path.join(root,dir_list))
if len(file_name_list) == 0:
pass
else:
print "Warning: These files has a problem!!!"
for filelists in file_name_list:
print filelists
if len(file_path_list) == 0:
pass
else:
print "\nWarning: These directorys has a problem!!!"
for dislists in file_path_list:
print dislists
转载于:https://blog.51cto.com/cyr520/1281639