Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #71745 > unrolled thread
| Started by | satishmlwizpro@gmail.com |
|---|---|
| First post | 2014-05-18 23:53 -0700 |
| Last post | 2014-05-21 22:53 -0700 |
| Articles | 19 — 7 participants |
Back to article view | Back to comp.lang.python
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
| From | satishmlwizpro@gmail.com |
|---|---|
| Date | 2014-05-18 23:53 -0700 |
| Subject | 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. |
| Message-ID | <e672c890-a0d2-4bf5-bd94-9fdf70b0d1d2@googlegroups.com> |
Hi, Consider /src/alias/a.c /src/alias/b.c /src/xml/p.xml /src/xml/c.xml /src/h.c as source directory and /dest/alias /dest/xml /dest as destination directory. These are given in a csv file like /src/alias/a.c, /dest/alias /src/alias/b.c, /dest/alias /src/xml/p.xml, /dest/xml /src/xml/c.xml, /dest/xml /src/h.c, /dest Python code should read csv file. Copy files from source to destination(files in /src/alias should be copied to /dest/alias and not to /dest/xml i.e., directory names should be the same). If /dest contains same files as /src, then they code should give us a warning and such files shouldn't be copied. Other files should only be copied. Could you kindly help?
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-05-19 17:01 +1000 |
| Message-ID | <mailman.10123.1400482872.18130.python-list@python.org> |
| In reply to | #71745 |
On Mon, May 19, 2014 at 4:53 PM, <satishmlwizpro@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
[toc] | [prev] | [next] | [standalone]
| From | Satish ML <satishmlwizpro@gmail.com> |
|---|---|
| Date | 2014-05-19 01:08 -0700 |
| Message-ID | <24bc5790-ed38-4e3e-9c8a-8282d3b7f453@googlegroups.com> |
| In reply to | #71746 |
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@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
Consider xls file contains source and destination directory paths.
import xlrd, sys, subprocess
file_location = "C:\Users\User1\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:
What next after this?
shutil.copy(src, dest) doesn't work because it overwrites dest files.
[toc] | [prev] | [next] | [standalone]
| From | Satish ML <satishmlwizpro@gmail.com> |
|---|---|
| Date | 2014-05-19 02:02 -0700 |
| Message-ID | <8ff7483f-cec3-4cc8-bedf-68da09571350@googlegroups.com> |
| In reply to | #71746 |
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@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.
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-05-19 22:57 -0700 |
| Message-ID | <89887b39-3988-45cf-9a26-02f3eeef9f22@googlegroups.com> |
| In reply to | #71749 |
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 ?
[toc] | [prev] | [next] | [standalone]
| From | Satish ML <satishmlwizpro@gmail.com> |
|---|---|
| Date | 2014-05-20 05:21 -0700 |
| Message-ID | <934ba77e-6794-4d41-a3f3-ca0e370c4afb@googlegroups.com> |
| In reply to | #71790 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Satish ML <satishmlwizpro@gmail.com> |
|---|---|
| Date | 2014-05-20 05:23 -0700 |
| Message-ID | <8c6b0cd8-becf-44d6-9988-0fc017922022@googlegroups.com> |
| In reply to | #71797 |
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" else shutil.copy(s, d)
[toc] | [prev] | [next] | [standalone]
| From | Satish ML <satishmlwizpro@gmail.com> |
|---|---|
| Date | 2014-05-20 05:24 -0700 |
| Message-ID | <575e4180-b222-4e8f-a378-f39a51c3c085@googlegroups.com> |
| In reply to | #71797 |
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)
[toc] | [prev] | [next] | [standalone]
| From | Satish ML <satishmlwizpro@gmail.com> |
|---|---|
| Date | 2014-05-20 05:28 -0700 |
| Message-ID | <45b38d71-bf27-4d8e-b912-1093bbb38dcb@googlegroups.com> |
| In reply to | #71799 |
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)
[toc] | [prev] | [next] | [standalone]
| From | alister <alister.nospam.ware@ntlworld.com> |
|---|---|
| Date | 2014-05-20 12:48 +0000 |
| Message-ID | <kaIev.271027$gT4.265474@fx01.am4> |
| In reply to | #71800 |
On Tue, 20 May 2014 05:28:09 -0700, Satish ML wrote: > 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) 1) Post your current code & any errors you are getting, this list is not a free software development house 2) Please clean up your posts before sending so that they are readable either use the mailing list https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. Thanks to Mark for the above paragraph I hope this is "Acceptable Usage" & not a copyright breach ;-) -- My weight is perfect for my height -- which varies.
[toc] | [prev] | [next] | [standalone]
| From | Jagadeesh Malakannavar <mnjagadeesh@gmail.com> |
|---|---|
| Date | 2014-05-20 21:35 +0530 |
| Message-ID | <mailman.10157.1400602844.18130.python-list@python.org> |
| In reply to | #71800 |
[Multipart message — attachments visible in raw view] — view raw
Hi Satish, Can you please send python part in plain text format? Python code here is difficult to read. Thanks On Tue, 20 May 2014, Satish ML wrote: | 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 = [] > dest | ination.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) |
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-05-20 18:29 -0700 |
| Message-ID | <2122e5a9-198d-4998-bebf-3f19fe110f57@googlegroups.com> |
| In reply to | #71811 |
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
[toc] | [prev] | [next] | [standalone]
| From | Satish ML <satishmlwizpro@gmail.com> |
|---|---|
| Date | 2014-05-21 01:41 -0700 |
| Message-ID | <99a414b6-0d02-40ac-9891-e179ff296db8@googlegroups.com> |
| In reply to | #71836 |
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'
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-05-21 11:12 +0200 |
| 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. |
| Message-ID | <mailman.10182.1400663582.18130.python-list@python.org> |
| In reply to | #71844 |
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
[toc] | [prev] | [next] | [standalone]
| From | Satish ML <satishmlwizpro@gmail.com> |
|---|---|
| Date | 2014-05-21 02:34 -0700 |
| Subject | 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. |
| Message-ID | <8389c3e9-1fa5-43a5-bee5-c64fe4ee0919@googlegroups.com> |
| In reply to | #71847 |
On Wednesday, May 21, 2014 2:42:49 PM UTC+5:30, Peter Otten wrote:
> 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
Hi,
On Wednesday, May 21, 2014 2:42:49 PM UTC+5:30, Peter Otten wrote:
> 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
Hi,
Source file exists in the directory.
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-05-21 12:15 +0200 |
| Subject | Re: Copying non-existing files |
| Message-ID | <mailman.10185.1400667342.18130.python-list@python.org> |
| In reply to | #71849 |
Satish ML wrote: [You're back to turd-formatted text; please find a permanent fix for this] > C:\Desktop\salingeg\dest\code > Traceback (most recent call last): > File > "C:\Users\salingeg\Desktop\excel_1.py", line 24, in <module> > shut > il.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 > > Hi, > > Source file exists in the directory. If you are *really* sure about this (please double-check) it may be a rights issue. Then make sure the user running the script has reading rights for the file.
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-05-21 07:14 -0700 |
| Subject | Re: Copying non-existing files |
| Message-ID | <10443c4a-5e1c-40bc-8c18-c696f6abde8f@googlegroups.com> |
| In reply to | #71851 |
On Wednesday, May 21, 2014 2:11:42 PM UTC+5:30, Satish ML wrote:
> import xlrd, sys, os, shutil
> for f in files:
> for s in source:
> for d in destination:
> print f
> print s
> print d
> if (os.path.exists("d\\f")):
Am I missing something very basic???
Should you be writing
"d\\f"
or
d ++ "\\" ++ f
?
On Wednesday, May 21, 2014 3:45:24 PM UTC+5:30, Peter Otten wrote:
>
> [You're back to turd-formatted text; please find a permanent fix for this]
>
Satish:
Please see https://mail.python.org/pipermail/python-list/2014-May/672340.html
to get an idea how your posts look to others here
Then see
https://mail.python.org/pipermail/python-list/2014-May/
to see how most posts look
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-05-22 00:45 +1000 |
| Subject | Re: Copying non-existing files |
| Message-ID | <mailman.10196.1400683519.18130.python-list@python.org> |
| In reply to | #71855 |
On Thu, May 22, 2014 at 12:14 AM, Rustom Mody <rustompmody@gmail.com> wrote: > d ++ "\\" ++ f ITYM: d + "\\" + f or possibly: d + "/" + f ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-05-21 22:53 -0700 |
| Subject | Re: Copying non-existing files |
| Message-ID | <6888fa58-4250-4227-a8d1-9dcceaa3bcda@googlegroups.com> |
| In reply to | #71861 |
On Wednesday, May 21, 2014 8:15:10 PM UTC+5:30, Chris Angelico wrote: > On Thu, May 22, 2014 at 12:14 AM, Rustom Mody wrote: > > > d ++ "\\" ++ f > > ITYM: > > d + "\\" + f > > or possibly: > > d + "/" + f Heh! I had a vague feeling it looked strange -- stack corrupted while context switching from haskell To OP: No you should use none of the above. Use join https://docs.python.org/2/library/os.path.html#os.path.join
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web