Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Help Needed. Removing a Folder Problem

Reply
Thread Tools

Help Needed. Removing a Folder Problem

 
 
Kilicaslan Fatih
Guest
Posts: n/a
 
      07-20-2006
When I push a button to trigger the code:

def runCCCC(self, event):
cmd_out = self.A_com()
if App.runF != "":
os.mkdir('C:\copiedFiles')

for item in App.runF:
App.beCopied = str(item)
shutil.copy(App.beCopied,
'C:\copiedFiles')
cmd = 'cccc C:\copiedFiles\*.*' + cmd_out
os.system(cmd)
shutil.rmtree('C:\copiedFiles')
else:
tkMessageBox.showinfo("Window Text",
"Please Firstly Browse and Insert A File")


I encountered this error:

Traceback (most recent call last):
File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345,
in __call__
return self.func(*args)
File "C:\Python24\TkScripts\RCFolder.py", line 61,
in runCCCC
shutil.rmtree('C:\copiedFiles',
ignore_errors=False)# OLMADI!!!
File "C:\Python24\lib\shutil.py", line 168, in
rmtree
onerror(os.remove, fullname, sys.exc_info())
File "C:\Python24\lib\shutil.py", line 166, in
rmtree
os.remove(fullname)
OSError: [Errno 13] Permission denied:
'C:\\copiedFiles\\Analog.c'

1. What I want to do is to get the list of files I
inserted to a Listbox,
2. Creating a folder,(C:\copiedFiles)
3. Copying all of these files to this folder with the
same names,
4. Running CCCC for all of the files in this folder,
5. Than removing this folder.

Can anyone enlighten me on this Error I have got and
how to solve it?

Regards


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      07-20-2006
Note the error is permission denied. I would guess that
either the file has read-only flag set or perhaps the
'cccc' program is still running and has the file open
in a separate thread so you can't delete the directory
until it has completed. You should take a look at the
subprocess module and use something like (not tested):

retcode = call([r'cccc C:\copiedfiles\*.*', cmd_out])

This will wait for execution of cccc to complete prior
to returning.

-Larry Bates


Kilicaslan Fatih wrote:
> When I push a button to trigger the code:
>
> def runCCCC(self, event):
> cmd_out = self.A_com()
> if App.runF != "":
> os.mkdir('C:\copiedFiles')
>
> for item in App.runF:
> App.beCopied = str(item)
> shutil.copy(App.beCopied,
> 'C:\copiedFiles')
> cmd = 'cccc C:\copiedFiles\*.*' + cmd_out
> os.system(cmd)
> shutil.rmtree('C:\copiedFiles')
> else:
> tkMessageBox.showinfo("Window Text",
> "Please Firstly Browse and Insert A File")
>
>
> I encountered this error:
>
> Traceback (most recent call last):
> File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345,
> in __call__
> return self.func(*args)
> File "C:\Python24\TkScripts\RCFolder.py", line 61,
> in runCCCC
> shutil.rmtree('C:\copiedFiles',
> ignore_errors=False)# OLMADI!!!
> File "C:\Python24\lib\shutil.py", line 168, in
> rmtree
> onerror(os.remove, fullname, sys.exc_info())
> File "C:\Python24\lib\shutil.py", line 166, in
> rmtree
> os.remove(fullname)
> OSError: [Errno 13] Permission denied:
> 'C:\\copiedFiles\\Analog.c'
>
> 1. What I want to do is to get the list of files I
> inserted to a Listbox,
> 2. Creating a folder,(C:\copiedFiles)
> 3. Copying all of these files to this folder with the
> same names,
> 4. Running CCCC for all of the files in this folder,
> 5. Than removing this folder.
>
> Can anyone enlighten me on this Error I have got and
> how to solve it?
>
> Regards
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com

 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      07-20-2006
Note the error is permission denied. I would guess that
either the file has read-only flag set or perhaps the
'cccc' program is still running and has the file open
in a separate thread so you can't delete the directory
until it has completed. You should take a look at the
subprocess module and use something like (not tested):

retcode = call([r'cccc C:\copiedfiles\*.*', cmd_out])

This will wait for execution of cccc to complete prior
to returning.

-Larry Bates


Kilicaslan Fatih wrote:
> When I push a button to trigger the code:
>
> def runCCCC(self, event):
> cmd_out = self.A_com()
> if App.runF != "":
> os.mkdir('C:\copiedFiles')
>
> for item in App.runF:
> App.beCopied = str(item)
> shutil.copy(App.beCopied,
> 'C:\copiedFiles')
> cmd = 'cccc C:\copiedFiles\*.*' + cmd_out
> os.system(cmd)
> shutil.rmtree('C:\copiedFiles')
> else:
> tkMessageBox.showinfo("Window Text",
> "Please Firstly Browse and Insert A File")
>
>
> I encountered this error:
>
> Traceback (most recent call last):
> File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345,
> in __call__
> return self.func(*args)
> File "C:\Python24\TkScripts\RCFolder.py", line 61,
> in runCCCC
> shutil.rmtree('C:\copiedFiles',
> ignore_errors=False)# OLMADI!!!
> File "C:\Python24\lib\shutil.py", line 168, in
> rmtree
> onerror(os.remove, fullname, sys.exc_info())
> File "C:\Python24\lib\shutil.py", line 166, in
> rmtree
> os.remove(fullname)
> OSError: [Errno 13] Permission denied:
> 'C:\\copiedFiles\\Analog.c'
>
> 1. What I want to do is to get the list of files I
> inserted to a Listbox,
> 2. Creating a folder,(C:\copiedFiles)
> 3. Copying all of these files to this folder with the
> same names,
> 4. Running CCCC for all of the files in this folder,
> 5. Than removing this folder.
>
> Can anyone enlighten me on this Error I have got and
> how to solve it?
>
> Regards
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com


 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      07-20-2006
Kilicaslan Fatih wrote:
[...]
> Dear All,
>
> I changed the mode of the files before copying them.
> So the problem is solved as follows:
>
> SOLUTION:
>
> def runCCCC(self, event):
> cmd_out = self.A_com()
> if App.runF != "":
> os.mkdir('C:\copiedFiles')
>
> for item in App.runF:
> os.chmod(item, 0700)
> shutil.copy(item, 'C:\copiedFiles')
>
> cmd = 'cccc C:\copiedFiles\*.*' + cmd_out
> os.system(cmd)
> for root,dir,files in
> os.walk("C:\copiedFiles"):
>
> shutil.rmtree('C:\copiedFiles')
> else:
> tkMessageBox.showinfo("Window Text",
> "Please Firstly Browse and Insert A File")
>

Just be careful with those string constants: you should really be using
either 'C:\\copiedFiles' or r'C:\copiedFiles'. No problems at the moment
because "\c" isn't a defined escape sequence, but if your directory name
had begun with a "t", for example, you'd have got a tab after the colon.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing GPO setting from XP machine after removing from Domain Piet Slaghekke Computer Support 4 01-02-2007 08:58 PM
removing a namespace prefix and removing all attributes not in that same prefix Chris Chiasson XML 6 11-14-2006 05:08 PM
Problem in adding new images ait folder from a selected folder madhu C++ 0 10-05-2006 07:24 AM
_vti_cnf folder in the bin folder-- a problem? William LaMartin ASP .Net 1 11-10-2003 03:41 AM
help: setting web folder as application folder in server THY ASP .Net 3 10-16-2003 01:18 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57