Python获取当前目录或者其他指定目录下所有文件的绝对路径并存储在文件中,程序如下:
import os fid = open('GetAbsolutePath.txt', 'w') rootdir = os.getcwd() # rootdir = 'D:\\test' # print('rootdir = ' + rootdir) pathname = [] for (dirpath, dirnames, filenames) in os.walk(rootdir): for filename in filenames: pathname += [os.path.join(dirpath, filename)] fid.write(str(pathname) fid.close()