在这里急需一些帮助。
我一直在尽力想出一个简单的程序,该程序将承担以下任务:
https://docs.google.com/document/d/1COBL4P6vqf3aVDm4OTJJcq-VDQ8f0TGVwvifJrpqPpE/edit?usp=sharing
不幸的是,我是一个完全的编程新手,我做的最多的是BASIC程序,所以无论如何,这就是我迄今为止所拥有的一切:
import filecmp
import os
import shutil
count = 0
while (count < 2):
if os.listdir ("E:\Test") ==[]:
shutil.copy2("\UsersAndrewDesktopTest.txt","E:TestTest.txt")
filecmp.cmp("\UsersAndrewDesktopTest.txt","E:TestTest.txt")
count = count + 1
break
else:
shutil.rmtree("E:\Test")
os.mkdir("E:\Test")
我在没有 While 循环的情况下运行了这个,但现在我完全困惑它只是无限循环。任何帮助都会很棒,谢谢!
对于那些感兴趣的人,这就是完成的程序的样子。
import filecmp
import os
import shutil
from datetime import datetime
#Imported all of the neccessary items for running the script
count = 0
read = 0
write = 0
copys = 0
fail = 0
delete = 0
data = shutil.disk_usage("E:\")
free = (data[2])
with open ("\Users\Andrew\Desktop\SD Card Testing\Test.txt","wb") as fout:
fout.write(os.urandom(int(free)))
file = os.path.getsize("\Users\Andrew\Desktop\SD Card Testing\Test.txt")
start = datetime.now()
while (fail == 0):
#While the fail count is == 0 then do:
if os.listdir ("E:\Test") ==[]:
read = read + 1
#Check if the Dir is empty
shutil.copy2("\Users\Andrew\Desktop\SD Card Testing\Test.txt","E:TestTest.txt")
copys = copys + 1
write = write + 1
print ((file*copys)/(1048576*1024),"GB")
if filecmp.cmp("\Users\Andrew\Desktop\SD Card Testing\Test.txt","E:TestTest.txt",shallow=False) == True:
print(filecmp.cmp("\Users\Andrew\Desktop\SD Card Testing\Test.txt","E:TestTest.txt",shallow=False))
read = read + 2
#If the result of the file check is true print
else:
fail = fail + 1
print ("Fail:",fail)
#If the result of the file check is false fail and break
else:
shutil.rmtree("E:\Test")
delete = delete + 1
os.mkdir("E:\Test")
write = write + 2
print ("Deletes:",delete)
#If the folder is not empty then remove it and replace
count = count + 1
print (count)
end = datetime.now()
print ("Duration: {}".format(end-start))
#When the loop breaks print the number of read/writes
print ("Read:",read)
print ("Write:",write)
我相信人们将能够提供有关改进的建议,但我目前有两组SD卡测试,大约2.5 TB写入256 mB分区。