2014-12-24 2 views
0

Настоятельно нужна помощь.Проверка SD-карты до отказа Программа Python

Я стараюсь изо всех сил, чтобы придумать простую программу (МОГ), которая будет выполнять следующие:

https://docs.google.com/document/d/1COBL4P6vqf3aVDm4OTJJcq-VDQ8f0TGVwvifJrpqPpE/edit?usp=sharing

К сожалению, я полный новичок с программированием, самое я сделал это Бейсик программа так или иначе, это все, что я до сих пор:

import filecmp 
import os 
import shutil 
count = 0 
while (count < 2): 
    if os.listdir ("E:\\Test") ==[]: 
     shutil.copy2("\\Users\Andrew\Desktop\Test.txt","E:\Test\Test.txt") 
     filecmp.cmp("\\Users\Andrew\Desktop\Test.txt","E:\Test\Test.txt") 
     count = count + 1 
     break 
else: 
    shutil.rmtree("E:\\Test") 
    os.mkdir("E:\\Test") 

у меня была работает без цикла While, но теперь я полностью смущенный это только петли бесконечно. Любая помощь вообще была бы фантастической благодарностью!

+0

Узнайте, как использовать отладчик, он сэкономит вам часы и часы – reggaeguitar

ответ

0

Для тех, кому это интересно, выглядит так, как выглядит завершенная программа.

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:\Test\Test.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:\Test\Test.txt",shallow=False) == True: 
      print(filecmp.cmp("\\Users\\Andrew\\Desktop\\SD Card Testing\\Test.txt","E:\Test\Test.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 ТБ записана на раздел 256 Мб.