该程序支持:
(1)python script_name.py。把当前目录及其下层目录中所有文件联合文件的路径写入一个文件中;
(2)python script_name.py output_file_name。指定输出的文件名。
import os
import sys
def get_file_with_path(file_path) :
file_path_list = []
for root,dirs,files in os.walk(file_path) :
if (len(files) != 0) :
for file in files :
#filter the temporary files
if file.endswith('.swp') == False :
file_path = os.path.join('%s\%s'%(root,file))
if os.path.isfile(file_path) :
file_path_list.append(file_path)
return file_path_list
if __name__ == '__main__' :
curr_path = os.getcwd()
file_path_list = []
file_path_list = get_file_with_path(curr_path)
#write all the file with path into one file
if len(sys.argv) == 1 :
with open('file_list.f','w') as file_handle :
for file_path in file_path_list :
file_handle.write("%s\n"%file_path)
else :
#get the input file name
file_output_name = sys.argv[1]
with open('%s'%file_output_name,'w') as file_handle :
for file_path in file_path_list :
file_handle.write("%s\n"%file_path)