[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

rmdir problem

royG

3/11/2008 10:36:00 AM

hi
i am checking if a directory exists and if it does i want to delete it
and its contents.then i want to create the directory before creating
files in it.

def myfolderops():
testdir='..\mytestdir'
#if dir exist remove it
if isdir(testdir):
rmdir(testdir)
#again create directory
mkdir(testdir)

I am working on WinXP and logged in as admin in WinXP. when there is
no dir called '..\mytestdir' or an empty dir this code works removing
and creating the directory.but if the directory exists with contents
already then it causes an error 145 when rmdir is executed.the message
says 'directory is not empty'
what should i do to correct this?
(i need to remove the dir with its contents because each time i will
be putting diff files into it and donot want them to be mixed with old
files)

thanks
RG
24 Answers

Paul Hankin

3/11/2008 10:38:00 AM

0

On Mar 11, 10:35 am, royG <roygeor...@gmail.com> wrote:
> i am checking if a directory exists and if it does i want to delete it
> and its contents.then i want to create the directory before creating
> files in it.

Have a look at shutil.rmtree

--
Paul Hankin

Tim Golden

3/11/2008 10:43:00 AM

0

royG wrote:
> hi
> i am checking if a directory exists and if it does i want to delete it
> and its contents.then i want to create the directory before creating
> files in it.
>
> def myfolderops():
> testdir='..\mytestdir'
> #if dir exist remove it
> if isdir(testdir):
> rmdir(testdir)
> #again create directory
> mkdir(testdir)
>
> I am working on WinXP and logged in as admin in WinXP. when there is
> no dir called '..\mytestdir' or an empty dir this code works removing
> and creating the directory.but if the directory exists with contents
> already then it causes an error 145 when rmdir is executed.the message
> says 'directory is not empty'
> what should i do to correct this?
> (i need to remove the dir with its contents because each time i will
> be putting diff files into it and donot want them to be mixed with old
> files)

Two things:

1) Use raw strings (r"..\blah") or forward slashes ("../blah") when
messing with path names under windows.

2) Check out the shutils module:

http://docs.python.org/lib/module-s...


TJG

royG

3/11/2008 10:54:00 AM

0

On Mar 11, 3:37 pm, Paul
> Have a look at shutil.rmtree
>
thanks Paul
RG

Danny McEvoy

10/18/2011 11:46:00 PM

0

On Oct 18, 5:55 pm, "RichL" <rpleav...@yahoo.com> wrote:
> "marcus" <marcus...@yahoo.com> wrote in message
>
> news:a91957ff-95cf-416c-ab5c-719362fcf489@gy7g2000vbb.googlegroups.com...
>
>
>
>
>
> > On Oct 18, 11:33 am, Billy <billybartlet...@yahoo.com> wrote:
> >> On Oct 17, 11:02 pm, "who?" <yourimageunre...@sbcglobal.net> wrote:
>
> >> > On Oct 17, 6:16 pm, Billy <billybartlet...@yahoo.com> wrote:
>
> >> > > On Oct 17, 7:05 pm, Donna <tom.r...@ix.netcom.com> wrote:
>
> >> > > > On Oct 17, 6:24 pm, Billy <billybartlet...@yahoo.com> wrote:
>
> >> > > > > On Oct 17, 12:55 pm, Donna <tom.r...@ix.netcom.com> wrote:
>
> >> > > > > > On Oct 17, 3:25 am, Fattuchus <fattuc...@yahoo.com> wrote:
>
> >> > > > > > > Applause.  Nice to see another poster here sees the light.
>
> >> > > > > > > I can't understand how someone can be a Beatles fan or a
> >> > > > > > > Lennon fan
> >> > > > > > > and not see Yoko for what she is.
>
> >> > > > > > You really can't understand how someone can be a fan?  When I
> >> > > > > > think of
> >> > > > > > The Beatles, Yoko is not part of the equation... well, not
> >> > > > > > usually,
> >> > > > > > anyway.  She really doesn't stand out for me in any way...
> >> > > > > > well, other
> >> > > > > > than the fact that she was part of May's life and that she's
> >> > > > > > often the
> >> > > > > > main topic on this newsgroup.  My thoughts are basically that
> >> > > > > > she was
> >> > > > > > John's 2nd wife... she's offbeat... avant-garde... she sings
> >> > > > > > funny...
> >> > > > > > stuff happened.  That's about it for me.
>
> >> > > > > > > There's a saying:  all that evil needs to succeed is for good
> >> > > > > > > men to
> >> > > > > > > remain silent.  Too many here remain silent and even attack
> >> > > > > > > the Yoko
> >> > > > > > > critics.
>
> >> > > > > > I always wondered what your goal is here in trying to convince
> >> > > > > > others
> >> > > > > > that Yoko is so evil.  What is it that you want them to feel or
> >> > > > > > to
> >> > > > > > do?  From what you wrote, above, it sounds as if you don't want
> >> > > > > > them
> >> > > > > > to be silent about it.  But is that all you want, or is it
> >> > > > > > something
> >> > > > > > more?  And even if they're vocal about it, what will that
> >> > > > > > accomplish?
>
> >> > > > > > In trying to understand this, I can say that, for myself, it
> >> > > > > > was
> >> > > > > > irritating to read gushing praise for Mrs. Harrison, knowing
> >> > > > > > the
> >> > > > > > whacky and cruel things that she did which was well-hidden from
> >> > > > > > the
> >> > > > > > general public.  However, they were mostly just brief
> >> > > > > > statements of
> >> > > > > > mine here, borne out of momentary bursts of frustration when
> >> > > > > > I'd
> >> > > > > > sometimes read a post from somebody who would say how classy
> >> > > > > > and
> >> > > > > > wonderful she is, deceived and unaware of many of the facts,
> >> > > > > > some of
> >> > > > > > which are documented.  But I wasn't on a mission to be the one
> >> > > > > > to
> >> > > > > > expose her or to get the newsgroup or the public to turn on
> >> > > > > > her.  My
> >> > > > > > feeling is that, spiritually, what she does is ultimately
> >> > > > > > between her
> >> > > > > > and her God, and life plays out just as it should.
>
> >> > > > > > And so I feel the same regarding Yoko.  Whatever it is that
> >> > > > > > happened,
> >> > > > > > she will someday have to face whatever it is that she did...
> >> > > > > > and,
> >> > > > > > again, life played out just as it should.  Her personal thought
> >> > > > > > process, her deeds, and her relationship with John is not
> >> > > > > > necessarily
> >> > > > > > for outsiders to comprehend or to judge.  A lot of it was made
> >> > > > > > public,
> >> > > > > > however, and you can react to it, but you can't expect others
> >> > > > > > to feel
> >> > > > > > what you do, or with the same intensity.  You have a reason for
> >> > > > > > so
> >> > > > > > strongly feeling the way you do, and many of us here don't
> >> > > > > > understand
> >> > > > > > it.  And that's okay since you may not fully understand it,
> >> > > > > > yourself.
> >> > > > > > But it's your thing, not ours.  After years of talking about
> >> > > > > > her here,
> >> > > > > > not much has changed in the way of swaying a lot of posters
> >> > > > > > over to
> >> > > > > > your point of view.  So why go on?  And why would the opinion
> >> > > > > > of
> >> > > > > > others even matter so much to you?  What are you looking for
> >> > > > > > them to
> >> > > > > > do with the information that you present?  Really, I'm just
> >> > > > > > curious,
> >> > > > > > fattuchus.  No disrespect intended here.
>
> >> > > > > Hi.  You express a lot if feelings in this post.  You weren't
> >> > > > > writing
> >> > > > > to me, but I did want to.mention that other people don't have to
> >> > > > > share
> >> > > > > your feelings.  I don't see why anyone should be expected to
> >> > > > > agree
> >> > > > > that everything Yoko did is "between herself and her god,"I for
> >> > > > > example.  You might be fine with whatever Yoko does, and
> >> > > > > confident God
> >> > > > > is, too.  Nut is that a reason for others to feel the same way?
> >> > > > > Don't others, possibly others who know more about Yoko than you,
> >> > > > > have
> >> > > > > the right to believe differently?  Even to be rubbed the wrong
> >> > > > > way by
> >> > > > > some of Yoko's doings?
>
> >> > > > Of course!  I was trying to relate for my own understanding, but I
> >> > > > wasn't expecting anyone to share my feelings or agree with how I
> >> > > > see
> >> > > > it.  Not in the least.  And not expecting others to share the same
> >> > > > feelings or trying to convince them of anything is kind of the
> >> > > > point.
> >> > > > I don't think you were really comprehending my questions.  Being
> >> > > > that
> >> > > > she brought up the saying, "All that evil needs to succeed is for
> >> > > > good
> >> > > > men to remain silent," I'm just curious as to what Fattuchus
> >> > > > ultimately hopes to accomplish here.
>
> >> > > My interpretation of that was that people can and should speak out
> >> > > when Yoko does or says something objectionable.
>
> >> > > "Evil" might be too strong for many people.  But I would agree based
> >> > > on Yoko's behavior over time that she's very arrogant, greedy, and
> >> > > obsessed with promoting herself, often in dishonest ways.
>
> >> > Whatever she does, what does that have to do with us? We can't
> >> > do anything about it.
>
> >> We can discuss it and those with the knowledge and the guts can even
> >> disagree with some of it.
>
> >> I believe Yoko is very concerned with how she is perceived.   Why do
> >> so much PR?  WHY-
>
> > Well, I don't think she does that much PR, and if she does apparently
> > it isn't getting noticed outside of the small circle of folks who post
> > here.  People I know, who aren't as much fans of The Beatles as you
> > and me, often respond to me when I mention Yoko's name, "Is she still
> > around...never hear anything about her anymore."
>
> Exactly.  This is what puzzles me most about those who claim, for example,
> that Yoko benefitted from John's death.  I mean, c'mon, people.  If John
> were still alive, it's a pretty fair bet that he'd be in the spotlight and
> Yoko would be there alongside him.
>
> Think, people!- Hide quoted text -
>
> - Show quoted text -

YO gained a lot from JLs death...an unbelievebly hell of a lot.

1) she gained eternal kudos as the widow of the world
2) Money
3) Control
4) rid of the pain in the backside that was her husband
5) eternal fame

Danny

abe slaney

10/19/2011 1:22:00 AM

0

On Oct 18, 7:45 pm, Danny McEvoy <thewalruswasda...@gmail.com> wrote:

> YO gained a lot from JLs death...an unbelievebly hell of a lot.
>
> 1) she gained eternal kudos as the widow of the world

Kudos is not the right word - it means "accolades." I think the word
you are looking for is "sympathy."

> 2) Money

She already controlled the money.

> 3) Control

See #2

> 4) rid of the pain in the backside that was her husband

No comment

> 5) eternal fame

She was already (in)famous.

> Danny

marcus

10/19/2011 2:53:00 AM

0

On Oct 18, 2:56 pm, "RichL" <rpleav...@yahoo.com> wrote:
> "Nil" <redno...@REMOVETHIScomcast.net> wrote in message
>
> news:Xns9F8296B182Enilch1@127.0.0.1...
>
> > On 18 Oct 2011, Donna <tom.r...@ix.netcom.com> wrote in
> > rec.music.beatles:
>
> >> Help me out here. Has anyone stated that she should not be
> >> criticized?
>
> > Yes: the fabled "Yoko sycophants." I believe Mr. Billy is preparing to
> > tell us us all about them shortly.
>
> I'd put the "fabled" in quotes and capitalize all the words.  Great band
> name, if I were ever interested in starting up playing for $$$ again, I'd
> consider it.
>
> The Fabled Yoko Sycophants!  Love it!

and they all moon the audience at the end of each performance with
their new song, "Bottoms". ;-)

Jeff

10/19/2011 4:25:00 AM

0

On Oct 18, 6:45 pm, Danny McEvoy <thewalruswasda...@gmail.com> wrote:
> On Oct 18, 5:55 pm, "RichL" <rpleav...@yahoo.com> wrote:
>
>
>
>
>
>
>
>
>
> > "marcus" <marcus...@yahoo.com> wrote in message
>
> >news:a91957ff-95cf-416c-ab5c-719362fcf489@gy7g2000vbb.googlegroups.com...
>
> > > On Oct 18, 11:33 am, Billy <billybartlet...@yahoo.com> wrote:
> > >> On Oct 17, 11:02 pm, "who?" <yourimageunre...@sbcglobal.net> wrote:
>
> > >> > On Oct 17, 6:16 pm, Billy <billybartlet...@yahoo.com> wrote:
>
> > >> > > On Oct 17, 7:05 pm, Donna <tom.r...@ix.netcom.com> wrote:
>
> > >> > > > On Oct 17, 6:24 pm, Billy <billybartlet...@yahoo.com> wrote:
>
> > >> > > > > On Oct 17, 12:55 pm, Donna <tom.r...@ix.netcom.com> wrote:
>
> > >> > > > > > On Oct 17, 3:25 am, Fattuchus <fattuc...@yahoo.com> wrote:
>
> > >> > > > > > > Applause.  Nice to see another poster here sees the light.
>
> > >> > > > > > > I can't understand how someone can be a Beatles fan or a
> > >> > > > > > > Lennon fan
> > >> > > > > > > and not see Yoko for what she is.
>
> > >> > > > > > You really can't understand how someone can be a fan?  When I
> > >> > > > > > think of
> > >> > > > > > The Beatles, Yoko is not part of the equation... well, not
> > >> > > > > > usually,
> > >> > > > > > anyway.  She really doesn't stand out for me in any way....
> > >> > > > > > well, other
> > >> > > > > > than the fact that she was part of May's life and that she's
> > >> > > > > > often the
> > >> > > > > > main topic on this newsgroup.  My thoughts are basically that
> > >> > > > > > she was
> > >> > > > > > John's 2nd wife... she's offbeat... avant-garde... she sings
> > >> > > > > > funny...
> > >> > > > > > stuff happened.  That's about it for me.
>
> > >> > > > > > > There's a saying:  all that evil needs to succeed is for good
> > >> > > > > > > men to
> > >> > > > > > > remain silent.  Too many here remain silent and even attack
> > >> > > > > > > the Yoko
> > >> > > > > > > critics.
>
> > >> > > > > > I always wondered what your goal is here in trying to convince
> > >> > > > > > others
> > >> > > > > > that Yoko is so evil.  What is it that you want them to feel or
> > >> > > > > > to
> > >> > > > > > do?  From what you wrote, above, it sounds as if you don't want
> > >> > > > > > them
> > >> > > > > > to be silent about it.  But is that all you want, or is it
> > >> > > > > > something
> > >> > > > > > more?  And even if they're vocal about it, what will that
> > >> > > > > > accomplish?
>
> > >> > > > > > In trying to understand this, I can say that, for myself, it
> > >> > > > > > was
> > >> > > > > > irritating to read gushing praise for Mrs. Harrison, knowing
> > >> > > > > > the
> > >> > > > > > whacky and cruel things that she did which was well-hidden from
> > >> > > > > > the
> > >> > > > > > general public.  However, they were mostly just brief
> > >> > > > > > statements of
> > >> > > > > > mine here, borne out of momentary bursts of frustration when
> > >> > > > > > I'd
> > >> > > > > > sometimes read a post from somebody who would say how classy
> > >> > > > > > and
> > >> > > > > > wonderful she is, deceived and unaware of many of the facts,
> > >> > > > > > some of
> > >> > > > > > which are documented.  But I wasn't on a mission to be the one
> > >> > > > > > to
> > >> > > > > > expose her or to get the newsgroup or the public to turn on
> > >> > > > > > her.  My
> > >> > > > > > feeling is that, spiritually, what she does is ultimately
> > >> > > > > > between her
> > >> > > > > > and her God, and life plays out just as it should.
>
> > >> > > > > > And so I feel the same regarding Yoko.  Whatever it is that
> > >> > > > > > happened,
> > >> > > > > > she will someday have to face whatever it is that she did....
> > >> > > > > > and,
> > >> > > > > > again, life played out just as it should.  Her personal thought
> > >> > > > > > process, her deeds, and her relationship with John is not
> > >> > > > > > necessarily
> > >> > > > > > for outsiders to comprehend or to judge.  A lot of it was made
> > >> > > > > > public,
> > >> > > > > > however, and you can react to it, but you can't expect others
> > >> > > > > > to feel
> > >> > > > > > what you do, or with the same intensity.  You have a reason for
> > >> > > > > > so
> > >> > > > > > strongly feeling the way you do, and many of us here don't
> > >> > > > > > understand
> > >> > > > > > it.  And that's okay since you may not fully understand it,
> > >> > > > > > yourself.
> > >> > > > > > But it's your thing, not ours.  After years of talking about
> > >> > > > > > her here,
> > >> > > > > > not much has changed in the way of swaying a lot of posters
> > >> > > > > > over to
> > >> > > > > > your point of view.  So why go on?  And why would the opinion
> > >> > > > > > of
> > >> > > > > > others even matter so much to you?  What are you looking for
> > >> > > > > > them to
> > >> > > > > > do with the information that you present?  Really, I'm just
> > >> > > > > > curious,
> > >> > > > > > fattuchus.  No disrespect intended here.
>
> > >> > > > > Hi.  You express a lot if feelings in this post.  You weren't
> > >> > > > > writing
> > >> > > > > to me, but I did want to.mention that other people don't have to
> > >> > > > > share
> > >> > > > > your feelings.  I don't see why anyone should be expected to
> > >> > > > > agree
> > >> > > > > that everything Yoko did is "between herself and her god,"I for
> > >> > > > > example.  You might be fine with whatever Yoko does, and
> > >> > > > > confident God
> > >> > > > > is, too.  Nut is that a reason for others to feel the same way?
> > >> > > > > Don't others, possibly others who know more about Yoko than you,
> > >> > > > > have
> > >> > > > > the right to believe differently?  Even to be rubbed the wrong
> > >> > > > > way by
> > >> > > > > some of Yoko's doings?
>
> > >> > > > Of course!  I was trying to relate for my own understanding, but I
> > >> > > > wasn't expecting anyone to share my feelings or agree with how I
> > >> > > > see
> > >> > > > it.  Not in the least.  And not expecting others to share the same
> > >> > > > feelings or trying to convince them of anything is kind of the
> > >> > > > point.
> > >> > > > I don't think you were really comprehending my questions.  Being
> > >> > > > that
> > >> > > > she brought up the saying, "All that evil needs to succeed is for
> > >> > > > good
> > >> > > > men to remain silent," I'm just curious as to what Fattuchus
> > >> > > > ultimately hopes to accomplish here.
>
> > >> > > My interpretation of that was that people can and should speak out
> > >> > > when Yoko does or says something objectionable.
>
> > >> > > "Evil" might be too strong for many people.  But I would agree based
> > >> > > on Yoko's behavior over time that she's very arrogant, greedy, and
> > >> > > obsessed with promoting herself, often in dishonest ways.
>
> > >> > Whatever she does, what does that have to do with us? We can't
> > >> > do anything about it.
>
> > >> We can discuss it and those with the knowledge and the guts can even
> > >> disagree with some of it.
>
> > >> I believe Yoko is very concerned with how she is perceived.   Why do
> > >> so much PR?  WHY-
>
> > > Well, I don't think she does that much PR, and if she does apparently
> > > it isn't getting noticed outside of the small circle of folks who post
> > > here.  People I know, who aren't as much fans of The Beatles as you
> > > and me, often respond to me when I mention Yoko's name, "Is she still
> > > around...never hear anything about her anymore."
>
> > Exactly.  This is what puzzles me most about those who claim, for example,
> > that Yoko benefitted from John's death.  I mean, c'mon, people.  If John
> > were still alive, it's a pretty fair bet that he'd be in the spotlight and
> > Yoko would be there alongside him.
>
> > Think, people!- Hide quoted text -
>
> > - Show quoted text -
>
> YO gained a lot from JLs death...an unbelievebly hell of a lot.
>
> 1) she gained eternal kudos as the widow of the world
> 2) Money
> 3) Control
> 4) rid of the pain in the backside that was her husband
> 5) eternal fame
>
> Danny

Oh, brother. We'll have to keep working at this until you
get things straightened out.

Jeff

10/19/2011 4:36:00 AM

0

On Oct 18, 6:41 pm, Donna <tom.r...@ix.netcom.com> wrote:
> On Oct 18, 7:14 pm, Jeff <yourimageunre...@yahoo.com> wrote:
>
> > On Oct 18, 1:34 pm, Donna <tom.r...@ix.netcom.com> wrote:
>
> > > On Oct 18, 2:23 pm, Donna <tom.r...@ix.netcom.com> wrote:
>
> > > > Jeff, your exact words were, "That saying doesn't apply to Yoko and
> > > > there is nothing to be gained by attacking her. She didn't commit a
> > > > crime."
>
> > > > I know I missed a zillion Yoko posts, but from that statement, alone,
> > > > it doesn't appear that you're saying that people "shouldn't criticize
> > > > Yoko."  You're merely saying that there's nothing to be gained by it.
> > > > In fact, I don't recall anyone ever stating or even implying such a
> > > > thing, but that's not to say that no one ever did.  Help me out here.
> > > > Has anyone stated that she should not be criticized?
>
> Um... You do realize that I was clarifying your position and helping
> you out here, right?

Yes.

 Maybe not.  :/  Hey, you're welcome just the
> same.

Huh?

>
>
>
>
>
>
> > > I should just add one more thing, Jeff.  If you're saying that the
> > > constant repetition bothers you, then why did you start this thread?
> > > Didn't you know how it would play out?
>
> > Smile, Donna. I'm asking you the same thing about questioning
> > Fatt? Smile some more.
>
> > 1. I really wrote this thread for Danny clowning around.
>
> > 2. I meant no harm to Fatt and should have said nothing.
> > Her and I are friends just like you and I, and UpserTom
> > are.
>
> > 3. Tom brings Paul into it. I don't know why.
>
> > 4. I was bored and started this thread just like people
> > go out and play ping pong or tennis.
>
> > :-)
>
> My question was neutral.

Right.

 By this and your previous response, you
> sound as if you're being defensive, and I don't have a clue as to why
> that would be.

Nothing for me to get defensive about.

 Oh, well.  Sometimes threads get to a point like this
> where misinterpretations and misunderstandings fly, and I just have to
> sigh and throw my hands up.... and know that I'm done.

It is a misunderstanding, Donna. I'm sorry you feel the way you
do.

Jeff

10/19/2011 4:52:00 AM

0

On Oct 18, 6:41 pm, Danny McEvoy <thewalruswasda...@gmail.com> wrote:
> > What are we supposed to do about it? She committed no crimes.
>
> She commited the crime of spitting the fabs up...

> Danny

I think they stayed together long enough as much as I
love them. Unlike many people, I enjoy their solo music,
and have listened to it much more the past 15 years
than the Beatles. I never thought I would get tired of
them, but it happened with the original releases.
The alternate takes of their music continue to interest
me.

Dang, my backspace key keeps sticking and tries to
erase all of my text.

Fattuchus

10/19/2011 8:31:00 AM

0

On Oct 18, 11:21 am, Billy <billybartlet...@yahoo.com> wrote:
> On Oct 17, 7:37 pm, Donna <tom.r...@ix.netcom.com> wrote:
>
> > On Oct 17, 7:16 pm, Billy <billybartlet...@yahoo.com> wrote:
>
> > > My interpretation of that was that people can and should speak out
> > > when Yoko does or says something objectionable.
>
> > What do you feel that will accomplish?  Let's say that one day,
> > something suddenly clicks here... a lightbulb goes on... and many
> > posters agree that what Yoko is doing is objectionable.  They speak
> > out on this newsgroup.  Loudly.  Then what?  We physically gang up on
> > her and try to stop her?  Or we find that something in her past was
> > objectionable and we go back and change the course of history?  If
> > it's just the satisfaction of knowing that other people feel the same
> > way, how would that make a difference?
>
> It depend on what you mean by making a difference.   I don't think
> anyone imagines he's changing the course of history.   But there's a
> little satisfaction on calling a person (! such as Yoko) on it when
> her arrogance and wealth allow her to.assume she can say or do
> whatever she pleases.   And what's the problem with that?  When people
> defend Yoko do you require that they 'make a difference" or 'change
> the course of history"?
>
>
Another thoughtful post.