Advertisement
xunilk

copy_files.py

Aug 13th, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.07 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import os, shutil
  3. from PyQt4.QtGui import QMessageBox, QInputDialog
  4.  
  5. def copyFiles():
  6.      
  7.     full_path = os.path.realpath(__file__)
  8.      
  9.     # Se muestra el dialogo para pedir el nombre del usuario
  10.     title = u"Dialogo"
  11.     msg = "Por favor, introduzca su Nombre:"
  12.      
  13.     name = QInputDialog.getText(None, title, msg)
  14.     # name es una tupla donde:
  15.     # name[0] retorna el text
  16.     # name[1] retorna el boton seleccionado    
  17.      
  18.     # Si se ha hecho click en Cancelar se sale de la funcion
  19.     if not name[1]:
  20.         QMessageBox.warning(None, u"Información", u"No se ha intoducido el Nombre")
  21.         return
  22.      
  23.     msg = u"Introduzca un número en coma flotante"
  24.      
  25.     d = QInputDialog.getDouble(None, title, msg, decimals= 5)
  26.      
  27.     # Si se ha hecho click en Cancelar se sale de la funcion
  28.     if not d[1]:
  29.         QMessageBox.warning(None, u"Información", u"No se ha introducido el valor")
  30.         return
  31.      
  32.     print "my double = ", d[0]
  33.      
  34.     if os.path.isfile(full_path) == True:
  35.          
  36.         my_path, file = os.path.split(full_path)
  37.          
  38.         new_path = my_path + "/" + name[0]
  39.          
  40.         if os.path.isdir(new_path) is True:
  41.             print "El directorio " + new_path + " ya existe"
  42.              
  43.         else:
  44.             os.mkdir(new_path)
  45.             print "El directorio " + new_path + " ha sido creado"
  46.              
  47.         names = os.listdir(my_path)
  48.          
  49.         print my_path
  50.          
  51.         lista = ['buffer.py', 'xxx.txt', 'xxx2.txt']
  52.          
  53.         lista_cop = [] #inicializa lista de archivos copiados
  54.          
  55.         for item in lista:
  56.             if item not in names:
  57.                 print "el archivo " + item + u" no está en el directorio"
  58.                 message = "El archivo \"" + item + u"\" no está en el directorio"
  59.                 QMessageBox.information(None, u"Información", message)
  60.          
  61.         names2 = os.listdir(new_path)
  62.          
  63.         for item in lista:
  64.             my_file = os.path.join(my_path, item)  
  65.              
  66.             if item in names2:
  67.                 msg = "El archivo " + item + " ya existe. Quiere sobrescribir el resultado(s/n)?"
  68.                 reply = QMessageBox.question(None, 'Question', msg, QMessageBox.Yes, QMessageBox.No)
  69.                  
  70.                 if reply == QMessageBox.Yes:
  71.                     shutil.copy(my_file, new_path)
  72.                     lista_cop.append(item)
  73.             else:
  74.                 if item in names:
  75.                     shutil.copy(my_file, new_path)
  76.                     lista_cop.append(item)
  77.          
  78.         if len(lista_cop) != 0:
  79.          
  80.             message = 'Copia finalizada con los siguientes archivos copiados: \n'
  81.              
  82.             for item in lista_cop:
  83.                 message += item + ", "
  84.              
  85.             QMessageBox.information(None, "Informacion", message)
  86.              
  87.         else:
  88.              
  89.             message = 'Cero archivos copiados'
  90.             QMessageBox.information(None, "Informacion", message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement