pjmakey2

iterar copiar verificar

Aug 7th, 2013
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import subprocess
  2. import os
  3. import shutil
  4.  
  5.  
  6. out = subprocess.Popen('ls', shell=True, stdout=subprocess.PIPE)
  7. lineas_c = out.stdout.readlines()
  8.  
  9. for a in lineas_c:
  10.     if os.path.isfile(a.strip()):
  11.         print 'Esto es un archivo %s' % a.strip()
  12.         print '\tEsta en la carpeta %s' % os.path.dirname(os.path.abspath(a.strip()))
  13.     if os.path.isdir(a.strip()):
  14.         print 'Esto es un directorio %s' % a.strip()
  15.         #copiando todosw los archivos de a a /tmp, (en un nivel)                                                                
  16.         absp = os.path.abspath(a.strip())
  17.         for d in os.listdir(absp):
  18.             if os.path.isfile(d.strip()):
  19.                 shutil.copy2(absp, '/tmp/%s' % a.strip())
Advertisement
Add Comment
Please, Sign In to add comment