一个关于判断文件夹或文件名是否有空格的小脚本,没啥大作用,自己练习瞎写的。
不过涉及到的知识点还挺多。
1
|
cat check_filename.py
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#!/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
|
本文转自 cyr520 51CTO博客,原文链接:http://blog.51cto.com/cyr520/1281639