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
Mon May 19 05:02:36 EDT 2014


On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote:
> On Mon, May 19, 2014 at 4:53 PM, <satishmlwizpro at gmail.com> wrote: > Could you kindly help? Sure. Either start writing code and then post when you have problems, or investigate some shell commands (xcopy in Windows, cp in Linux, maybe scp) that can probably do the whole job. Or pay someone to do the job for you. ChrisA

Hi ChrisAngelico,

Consider that source and destination directories are given in a .xls(excel) file.

This is the code

import xlrd, sys, subprocess
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):
  
            values = []
   
            values.append(sheet.cell_value(row, 1))
            
  
            destination = []
            destination.append(sheet.cell_value(row, 2))
            
            
            for s in values:
                        
                        for d in destination:
                                                                                                            
If I am using cp or xcopy command, it will copy all files from s to d.
shutil.copy(s, d) can't be used here because it overwrites files in d. Kindly help.



More information about the Python-list mailing list