Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71800

Re: 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.

Newsgroups comp.lang.python
Date 2014-05-20 05:28 -0700
References (1 earlier) <mailman.10123.1400482872.18130.python-list@python.org> <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com>
Message-ID <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> (permalink)
Subject Re: 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.
From Satish ML <satishmlwizpro@gmail.com>

Show all headers | View raw


On Tuesday, May 20, 2014 5:54:47 PM UTC+5:30, Satish ML wrote:
> On Tuesday, May 20, 2014 5:51:19 PM UTC+5:30, Satish ML wrote: > On Tuesday, May 20, 2014 11:27:01 AM UTC+5:30, Rustom Mody wrote: > On Monday, May 19, 2014 2:32:36 PM UTC+5:30, Satish ML wrote: > On Monday, May 19, 2014 12:31:05 PM UTC+5:30, Chris Angelico wrote: > > On Mon, May 19, 2014 at 4:53 PM, 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. have u tried using https://docs.python.org/2/library/os.path.html#os.path.exists ? I have tried it. But how does it help? We won't be able to make out whether source file is present in destination directory. If we can do that, like if (source file exists in destination directory) print "exists" continue else shutil.copy(s, d)

Here we don't have the option of manually giving the file path. It has to be read from .xls file (i.e. from the two lists in code)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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. satishmlwizpro@gmail.com - 2014-05-18 23:53 -0700
  Re: 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. Chris Angelico <rosuav@gmail.com> - 2014-05-19 17:01 +1000
    Re: 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@gmail.com> - 2014-05-19 01:08 -0700
    Re: 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@gmail.com> - 2014-05-19 02:02 -0700
      Re: 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. Rustom Mody <rustompmody@gmail.com> - 2014-05-19 22:57 -0700
        Re: 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@gmail.com> - 2014-05-20 05:21 -0700
          Re: 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@gmail.com> - 2014-05-20 05:23 -0700
          Re: 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@gmail.com> - 2014-05-20 05:24 -0700
            Re: 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@gmail.com> - 2014-05-20 05:28 -0700
              Re: 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. alister <alister.nospam.ware@ntlworld.com> - 2014-05-20 12:48 +0000
              Re: 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. Jagadeesh Malakannavar <mnjagadeesh@gmail.com> - 2014-05-20 21:35 +0530
                Re: 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. Rustom Mody <rustompmody@gmail.com> - 2014-05-20 18:29 -0700
                Re: 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@gmail.com> - 2014-05-21 01:41 -0700
                Copying non-existing files, was Re: 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. Peter Otten <__peter__@web.de> - 2014-05-21 11:12 +0200
                Re: Copying non-existing files, was Re: 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@gmail.com> - 2014-05-21 02:34 -0700
                Re: Copying non-existing files Peter Otten <__peter__@web.de> - 2014-05-21 12:15 +0200
                Re: Copying non-existing files Rustom Mody <rustompmody@gmail.com> - 2014-05-21 07:14 -0700
                Re: Copying non-existing files Chris Angelico <rosuav@gmail.com> - 2014-05-22 00:45 +1000
                Re: Copying non-existing files Rustom Mody <rustompmody@gmail.com> - 2014-05-21 22:53 -0700

csiph-web