Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same name.

Satish ML satishmlwizpro at gmail.com
Wed May 21 04:41:42 EDT 2014


On Wednesday, May 21, 2014 6:59:40 AM UTC+5:30, Rustom Mody wrote:
> On Tuesday, May 20, 2014 9:35:10 PM UTC+5:30, Jagadeesh N. Malakannavar wrote: > Hi Satish, > > Can you please send python part in plain text format? Python code here is > > difficult to read. It would be helpful to read https://wiki.python.org/moin/GoogleGroupsPython#Posting_from_Google_Groups Note particularly the 2 standard expectations: - Dont top post - Dont use excessively long (> 70 chars) lines

Hi,

Here is the code.


xls file looks as follows:
a.c	C:\Desktop\salingeg\src\code\a.c	C:\Desktop\salingeg\dest\code
hello.txt	C:\Desktop\salingeg\src\txt\hello.txt	C:\Desktop\salingeg\dest\txt
integration.doc	C:\Desktop\salingeg\src\doc\integration.doc	C:\Desktop\salingeg\dest\doc
UG.doc	C:\Desktop\salingeg\src\doc\UG.doc	C:\Desktop\salingeg\dest\doc
Applications.xml	C:\Desktop\salingeg\src\xml\Applications.xml	C:\Desktop\salingeg\dest\xml
Platforms.xml	C:\Desktop\salingeg\src\xml\Platforms.xml	C:\Desktop\salingeg\dest\xml
avc.alias	C:\Desktop\salingeg\src\cnx\alias\avc.alias	C:\Desktop\salingeg\dest\cnx\alias
cats.alias	C:\Desktop\salingeg\src\cnx\alias\cats.alias	C:\Desktop\salingeg\dest\cnx\alias
avc.init	C:\Desktop\salingeg\src\cnx\init\avc.init	C:\Desktop\salingeg\dest\cnx\init
cats.init	C:\Desktop\salingeg\src\cnx\init\cats.init	C:\Desktop\salingeg\dest\cnx\init
		
		
PYTHON SCRIPT:

import xlrd, sys, os, shutil

file_location = "C:\Users\salingeg\Desktop\input.xls"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
sheet.cell_value(0, 0)
for row in range(sheet.nrows):
        source = []
        source.append(sheet.cell_value(row, 1))
        destination = []
        destination.append(sheet.cell_value(row, 2))
        files = []
        files.append(sheet.cell_value(row, 0))
        for f in files:
                for s in source:
                        for d in destination:
                                print f
                                print s
                                print d
                                if (os.path.exists("d\\f")):
                                        print ('File exists')
                                else:
                                        shutil.copy(s, d)
                
I am getting the following error:

a.c
C:\Desktop\salingeg\src\code\a.c
C:\Desktop\salingeg\dest\code
Traceback (most recent call last):
  File "C:\Users\salingeg\Desktop\excel_1.py", line 24, in <module>
    shutil.copy(s, d)
  File "C:\Program Files (x86)\python26\lib\shutil.py", line 84, in copy
    copyfile(src, dst)
  File "C:\Program Files (x86)\python26\lib\shutil.py", line 50, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: u'C:\\Desktop\\salingeg\\src\\code\\a.c'





More information about the Python-list mailing list