Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Deleting files and folders

    I am using ActivePerl-5.10.0.1004 and just need 2 simple scripts. One to delete a specific folder, contents and all, and another to delete specific files inside a folder. I have been searcing perl programming books but I can not find such delete commands. Free cookie to the one who can help me.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,942
    Thanks
    2
    Thanked 169 Times in 164 Posts
    What have you tried?

    What errors/warnings are you receiving?

    The function to delete files is unlink
    http://perldoc.perl.org/functions/unlink.html

    If you need to remove directory trees, then use the File::Path module.
    http://search.cpan.org/~dland/File-Path-2.08/Path.pm

  • #3
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have tried both of these but I have not gotten any errors or warnings. It just does not do anything.

  • #4
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is all I have left after many attempts

    @filelist = ("C:\Users\SSgt Toppin\AppData\Roaming\Microsoft\Windows\Cookies\Low\ssgt_toppin@nfl[2].txt");
    unlink @filelist;

  • #5
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,942
    Thanks
    2
    Thanked 169 Times in 164 Posts
    Either use forward slashes or escape the backslashes.

    Also, @nfl[2] is an array slice, which is not what you want to use here.

    Finally, Your @filelist array will consist of only that 1 element/filename, so why use an array?

    Code:
    my $filelist = ("C:/Users/SSgt Toppin/AppData/Roaming/Microsoft/Windows/Cookies/Low/ssgt_toppin$nfl[2].txt");
    
    unlink $filelist;

  • #6
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That is part of the filename. Not an array.

  • #7
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Code:
    ssgt_toppin@nfl[2].txt
    might be part of the filename buit what FishMonger was referring to was your use of
    Code:
     @filelist
    That is an array with just 1 item - that file ssgt_toppin@nfl[2].txt

    so its better to use a string than an array, as was suggested.



    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #8
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,942
    Thanks
    2
    Thanked 169 Times in 164 Posts
    If @nfl[2] is a literal part of the actual filename and not an array slice, then you need to escape the @ symbol or put the string in single quotes so that perl doesn't try to interpolate it as an array slice.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •