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


Groups > comp.lang.python > #71847

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.

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'read.': 0.03; 'interpreter': 0.05; '21,': 0.07; 'error:': 0.07; 'modify': 0.07; 'subject:same': 0.07; 'wednesday,': 0.07; 'executed': 0.09; 'filename': 0.09; 'overflow': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'shutil': 0.09; 'subject:files': 0.09; 'subject:into': 0.09; 'sys,': 0.09; 'python': 0.11; '"d"': 0.16; '"f"': 0.16; "'rb')": 0.16; '0))': 0.16; '24,': 0.16; 'dst)': 0.16; 'exist.': 0.16; 'files:': 0.16; 'folder,': 0.16; 'format?': 0.16; 'ioerror:': 0.16; 'path.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subdirectory': 0.16; 'subject:already': 0.16; 'subject:non': 0.16; 'subject:sub': 0.16; 'subject:under': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; 'skip:f 30': 0.19; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'exists': 0.24; 'script.': 0.24; 'url:moin': 0.24; 'helpful': 0.24; 'looks': 0.24; 'source': 0.25; 'options': 0.25; 'skip:" 30': 0.26; 'post': 0.26; 'excel': 0.26; 'somewhere': 0.26; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'skip:( 20': 0.30; 'code': 0.31; 'getting': 0.31; 'lines': 0.31; 'url:wiki': 0.31; '50,': 0.31; 'os,': 0.31; 'file': 0.32; 'there.': 0.32; 'skip:c 30': 0.32; 'text': 0.33; 'url:python': 0.33; '(most': 0.33; 'plain': 0.33; 'subject:from': 0.34; 'subject:with': 0.35; 'skip:s 30': 0.35; 'add': 0.35; 'hi,': 0.36; 'url:org': 0.36; 'follows:': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'recent': 0.39; 'subject:': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'called': 0.40; 'according': 0.40; 'how': 0.40; 'remove': 0.60; 'read': 0.60; 'such': 0.63; 'here': 0.66; 'dont': 0.67; '20,': 0.68; 'directory:': 0.84; 'subject:source': 0.84; 'destination': 0.91; 'sheet': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject 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.
Date Wed, 21 May 2014 11:12:49 +0200
Organization None
References <e672c890-a0d2-4bf5-bd94-9fdf70b0d1d2@googlegroups.com> <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> <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> <mailman.10157.1400602844.18130.python-list@python.org> <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> <99a414b6-0d02-40ac-9891-e179ff296db8@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd8888.dip0.t-ipconnect.de
User-Agent KNode/4.11.5
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10182.1400663582.18130.python-list@python.org> (permalink)
Lines 100
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1400663582 news.xs4all.nl 2877 [2001:888:2000:d::a6]:56505
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:71847

Show key headers only | View raw


Satish ML wrote:

[Regarding subject: let's see if we can trigger a buffer overflow somewhere 
;)]

> 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")):

The following line will either always be executed if you have a subdirectory 
"d" in your current working directory and that directory contains a file 
called "f" (unlikely) or never if "d\\f" doesn't exist (likely). 

Have a look at os.path.join() for the right way to join a directory with a 
filename into a path. Use the interactive interpreter to make sure you get 
the desired result and understand how it works before you fix your script.

>                                         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'

According to the error message the file you are trying to copy doesn't 
exist. Have a look into the C:\Desktop\salngeg\src\code folder, and check 
whether a file called a.c is there. If not you have three options

- add the file
- remove the line from the excel file
- modify the code to check if the *source* file exists

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