基本要求:
●编写代码实现文件复制,具体要求(注:都要通过代码实现):在电脑桌面新建一个文件夹,名为‘test_file1’,然后将电脑上的某个文件(任意选定)复制到该文件夹,并打印出该文件的总大小(字节数)。
●再将上述选定的文件内容以字节为单位倒序排列后形成一个新文件,将这个新文件存储到上述文件夹。
import os, sys
from tqdm import tqdm
path = "C:/Users/Bo/Desktop/test_file1"
os.mkdir(path)
aa = []
bb = []
with open(file="C:/Users/Bo/Desktop/test_file1.txt", mode="r") as r:
aa = r.read()
with open(file="C:/Users/Bo/Desktop/test_file1/test_file1.txt", mode="w") as w:
w.write(aa)
file_size = os.path.getsize("C:/Users/Bo/Desktop/test_file1/test_file1.txt")
for i in str(aa):
bb.insert(0, i)
with open(file="C:/Users/Bo/Desktop/test_file1/test_file2.txt", mode="w") as w:
w.writelines(bb)
print("桌面复制的文件大小为{}" .format(file_size))
课程上机任务小练习
如有不足 多多指教