Delete Folders

Discussion in 'Perl Misc' started by Rich Bogle, Apr 28, 2004.

  1. Rich Bogle

    Rich Bogle Guest

    Is there a better way to delete folders than this?

    $deletefolder = $compresspath . "/" . $folderlist;
    unlink glob "$deletefolder/* $deletefolder/.*";
    rmdir $deletefolder;
    Rich Bogle, Apr 28, 2004
    #1
    1. Advertising

  2. Rich Bogle

    Paul Lalli Guest

    On Wed, 28 Apr 2004, Rich Bogle wrote:

    > Is there a better way to delete folders than this?
    >
    > $deletefolder = $compresspath . "/" . $folderlist;
    > unlink glob "$deletefolder/* $deletefolder/.*";
    > rmdir $deletefolder;


    I could be wrong, but wouldn't this only remove all files actually in
    $deletefolder, and none of the files in any of its subdirectories? It
    would therefore not actually delete the directory.

    A better option is File::path::rmtree(), which I believe is in the
    standard distribution.

    perldoc File::path for more info

    Paul Lalli
    Paul Lalli, Apr 28, 2004
    #2
    1. Advertising

  3. Rich Bogle

    Paul Lalli Guest

    On Wed, 28 Apr 2004, Purl Gurl wrote:

    > Rich Bogle wrote:
    >
    > > Is there a better way to delete folders than this?

    >
    > > $deletefolder = $compresspath . "/" . $folderlist;
    > > unlink glob "$deletefolder/* $deletefolder/.*";
    > > rmdir $deletefolder;

    >
    >
    > \rm -rf directory_name
    >
    > That command is _extremely_ dangerous. A single
    > mistake can delete most or all of your directories
    > and contained files.


    Not to mention that it's unix-specific. The OP is calling directories
    'folers', which often indicates they're working on a Windows platform.

    Not especially what I'd call a 'better way'.

    Paul Lalli
    Paul Lalli, Apr 28, 2004
    #3
  4. Rich Bogle

    Paul Lalli Guest

    On Wed, 28 Apr 2004, Purl Gurl wrote:

    > Paul Lalli wrote:
    >
    > > Purl Gurl wrote:
    > > > Rich Bogle wrote:

    >
    > > > > Is there a better way to delete folders than this?

    >
    > > > \rm -rf directory_name

    >
    > > > That command is _extremely_ dangerous. A single
    > > > mistake can delete most or all of your directories
    > > > and contained files.

    >
    > > Not to mention that it's unix-specific. The OP is calling directories
    > > 'folers', which often indicates they're working on a Windows platform.

    >
    >
    > "folders"
    >
    > Unix, Linux, OS/2, Windows, DOS, folders are directories.
    >


    Do you enjoy getting into flame wars about pointless and off-topic
    discussions? I don't remember ever hearing the term 'folders' until
    Windows started using little file-folder icons for directories in the
    Program Manager of Win 3.0. I will freely admit in this case that other
    OSs might have used that term previously, as I was rather unfamiliar with
    Unix in those days.. Note however, that I said "often indicates" - as in,
    "it has been my experience that". If your experience is different, so be
    it.

    > "Not to mention...."
    >
    > Why did you mention this?


    Please learn generic English phrases. You clearly don't understand the
    basics.

    > Oxymoron, yes?


    Please consider purchasing a dictionary. You clearly don't understand the
    definition of this word, as there was no oxymoron anywhere in this thread.

    > deltree /y is equally dangerous under MSDOS.


    Which is exactly why it, along with rm -rf, should not have been mentioned
    in a response to a post asking for "a better way"

    > Any other specific system commands you wish to use
    > for critique? Perhaps this is another one of those
    > "a whole number is decimal number" thoughts of yours?


    Which you still haven't adequately responded too, after having the
    dictionary definition displayed for you, flat out contradicting your
    definition. But that's another thread entirely.


    > Not to mention sarcasm.


    Once again, your use of this phrase indicates your total lacking of
    understanding. I reiterate my second point above.


    Paul Lalli
    Paul Lalli, Apr 28, 2004
    #4
  5. Purl Gurl wrote:

    > deltree /y is equally dangerous under MSDOS.


    I was going to mention that, but it doesn't exist in XP. I wonder when that
    happened?

    FWIW, I agree with you this time. What's the point in writing a whole pile
    of Perl to do something a single system() call could do equally well?

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
    Sherm Pendley, Apr 28, 2004
    #5
  6. Rich Bogle

    Rich Bogle Guest

    "Rich Bogle" <> wrote in message
    news:c6oth0$2cvp$...
    > Is there a better way to delete folders than this?
    >
    > $deletefolder = $compresspath . "/" . $folderlist;
    > unlink glob "$deletefolder/* $deletefolder/.*";
    > rmdir $deletefolder;
    >
    >


    rmtree looks like a winner to me.

    Thanks Paul.
    Rich Bogle, Apr 28, 2004
    #6
  7. Rich Bogle

    Paul Lalli Guest

    On Wed, 28 Apr 2004, Sherm Pendley wrote:

    > Purl Gurl wrote:
    >
    > > deltree /y is equally dangerous under MSDOS.

    >
    > I was going to mention that, but it doesn't exist in XP. I wonder when that
    > happened?
    >
    > FWIW, I agree with you this time. What's the point in writing a whole pile
    > of Perl to do something a single system() call could do equally well?


    Because a system() call can't do it equally well, for one - it would
    require a code change to move between platforms. Also, it was ambiguous
    in the original post as to whether this was the only task required
    of the program, or if this was simply one component of a larger picture.

    Paul Lalli
    Paul Lalli, Apr 28, 2004
    #7
  8. Rich Bogle

    Paul Lalli Guest

    On Wed, 28 Apr 2004, Purl Gurl wrote:

    > Paul Lalli wrote:
    >
    > > Sherm Pendley wrote:
    > > > Purl Gurl wrote:

    >
    > (snipped)
    >
    > > Also, it was ambiguous in the original post...

    >
    > Previously you adamantly claimed the originating
    > author is using a Windows system, although you
    > did not specify which Windows system. Maybe 3.x?
    >
    > Now you are claiming ambiguity.
    >
    > My goodness!
    >
    > This is what happens when you deliberately
    > post troll articles in this group; humiliation.


    Do you honestly think snipping the relevant part of a post will disable
    people from figuring out what really happened? They can read the
    originals themselves, you know. You would make one hell of a TV news
    journalist, however.

    The piece you helpfully snipped here was:

    > Also, it was ambiguous in the original post as to whether this was the
    > only task required of the program, or if this was simply one component
    > of a larger picture.


    Explain to me what that has to do with the operating system the OP is
    using?
    Paul Lalli, Apr 28, 2004
    #8
  9. Rich Bogle

    Jim Cochrane Guest

    In article <>, Paul Lalli wrote:
    > On Wed, 28 Apr 2004, Purl Gurl wrote:
    >
    >> Paul Lalli wrote:
    >>
    >> > Purl Gurl wrote:
    >> > ...

    >> "folders"
    >>
    >> Unix, Linux, OS/2, Windows, DOS, folders are directories.
    >>

    >
    > Do you enjoy getting into flame wars about pointless and off-topic
    > discussions? I don't remember ever hearing the term 'folders' until
    > Windows started using little file-folder icons for directories in the
    > Program Manager of Win 3.0. I will freely admit in this case that other
    > OSs might have used that term previously, as I was rather unfamiliar with
    > Unix in those days.. Note however, that I said "often indicates" - as in,
    > "it has been my experience that". If your experience is different, so be
    > it.


    I believe I first encountered the term "folder" while using the GEM desktop
    environment on the Atari OS on an Atari ST in the late 1980s :)

    --
    Jim Cochrane;
    [When responding by email, include the term non-spam in the subject line to
    get through my spam filter.]
    Jim Cochrane, Apr 28, 2004
    #9
  10. Purl Gurl <> wrote:

    > I should correct my syntax.
    >
    > deltree directory_name /y
    >
    > I didn't know this is missing under Win XP systems.
    >
    > As NT5 systems "progress" MSDOS is being stripped out. You
    > might be able to add this back in. I know you can add a lot of
    > DOS features back in by downloading DOS 6.22 and adding those
    > features you want.


    Installing the ancient DOS 6.22 is certainly not a good solution.
    The solution is to use the right command: "rmdir" or "del."

    rmdir /s /q DIR
    del /s /q /f DIR

    Peter

    --
    #!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
    # matlab comment stripper (strips comments from Matlab m-files)
    s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
    Peter J. Acklam, Apr 29, 2004
    #10
  11. Purl Gurl wrote:

    >
    > Inherently, there also significant challenges, using Perl,
    > to find a selected system program and which directory
    > path separators to use for a system call. Ping!
    >
    >
    > if (-x "c:/windows/ping.exe")
    > { $ping = "c:\\windows\\ping.exe"; }
    > elsif ( -x "/bin/ping")
    > { $ping = "/bin/ping"; }

    This cries out for a loop.
    my @pingLocations = qw(/bin/ping /usr/sbin/ping);
    my ($ping) = grep { -x $_ } @pingLocations;
    print $ping;

    or something, or you could just rely on the path.

    Mark
    Mark Clements, Apr 29, 2004
    #11
  12. Purl Gurl <> wrote:

    > Peter J. Acklam wrote:
    >
    > > Installing the ancient DOS 6.22 is certainly not a good solution.

    >
    > You are practicing deliberate deceit.
    >
    > I did not state reinstallation of DOS files under
    > NT is a solution to the originating author's task.


    I never said you stated so either. You have been here so long,
    and you don't seem to have changed a bit.

    Peter

    --
    #!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
    # matlab comment stripper (strips comments from Matlab m-files)
    s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
    Peter J. Acklam, Apr 29, 2004
    #12
  13. GreenLight wrote:
    > There was never any "MSDOS" in Windows NT to "strip out". There is a
    > command interpreter, that doesn't mean that it is MSDOS.


    Actually, there are two command interpreters, COMMAND.COM, essentially
    the DOS command interpreter, and CMD.EXE, the native NT interpreter.

    --
    John W. Kennedy
    "Those in the seat of power oft forget their failings and seek only the
    obeisance of others! Thus is bad government born! Hold in your heart
    that you and the people are one, human beings all, and good government
    shall arise of its own accord! Such is the path of virtue!"
    -- Kazuo Koike. "Lone Wolf and Cub: Thirteen Strings" (tr. Dana Lewis)
    John W. Kennedy, Apr 30, 2004
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Ter-Saakov
    Replies:
    2
    Views:
    4,591
    Cesar Ronchese
    Jan 9, 2006
  2. Sandeep Grover

    delete on delete !

    Sandeep Grover, Jul 12, 2003, in forum: C++
    Replies:
    19
    Views:
    609
    Chris \( Val \)
    Jul 22, 2003
  3. HeroOfSpielburg
    Replies:
    1
    Views:
    379
    Alf P. Steinbach
    Aug 6, 2003
  4. fishinthenet
    Replies:
    0
    Views:
    1,646
    fishinthenet
    May 28, 2009
  5. Apostolis K.

    cannot script-delete / script-move folders

    Apostolis K., Jan 31, 2004, in forum: ASP General
    Replies:
    12
    Views:
    210
    Apostolis K.
    Feb 3, 2004
Loading...

Share This Page