Discuss / Python / 交作业

交作业

Topic source
import os,time

def time_format(x):
	return time.asctime(time.localtime(x))

#第一题
def cmd_dir():
	path = os.path.abspath('.')
	dir_and_file = [x for x in os.listdir('.')]
	gettime = list(map(time_format,map(os.path.getmtime,dir_and_file)))
	getsize = list(map(os.path.getsize,dir_and_file))
	n = 0
	while n < len(dir_and_file):
		print(gettime[n],' ==> ',getsize[n],' ==> ',dir_and_file[n])
		n += 1
#第二题
def findstrr(path,st):
	for x in os.listdir(path):
		if os.path.isdir(x):
			new_path = os.path.join(path,x)
			findstrr(new_path,st)
		elif st in os.path.splitext(x)[0]:
			print("相关文件名:%s, 相对路径:  %s" % (x,os.path.relpath(path)))


if __name__ == '__main__':
	f = os.path.abspath('.')
	text = input('input: ')
	findstrr(f,text)

  • 1

Reply