Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

current directory

by Anonymous Monk
on Jul 01, 2013 at 04:04 UTC ( #1041726=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hey i wish to remove a temporary file in the current directory so i am doing this
my $rm_file = "temporary.tl"; unlink($rm_file) ;
now the file is not being removed , so i am assuming that what I am doing is not working on current directory , so i wish to remove the temporary file from current directory , so please help

Replies are listed 'Best First'.
Re: current directory
by Athanasius (Archbishop) on Jul 01, 2013 at 04:13 UTC
      hey it says "permission denied "

        Hey, you just discovered your problem (and it ain't Perl).


        Dave

Re: current directory
by kcott (Archbishop) on Jul 01, 2013 at 04:36 UTC

    Apart from the file not existing in the current directory, you may not have appropriate permissions to delete the file or the problem may be as simple as mistyping the file's name. Here's a number of tools you may find useful:

    • unlink can tell you why the file wasn't deleted.
    • Use Cwd to determine what the current directory is.
    • Use chdir to change the current directory.
    • Use file test operators to check for the existence of the file and what its permissions are.
    • Use opendir and readdir to list all the files in a particular directory.
    • Use qx{...} or `...` (see perlop - Quote-Like Operators) to run whatever commands are available on your OS to do any of the above.

    -- Ken

      file names are same ; and i did cwd , it still says the same error . i was hoping is there any command that brings us to the current directory ? and if anyone can please state what could be the reason for permission deniale
        "file names are same ; and i did cwd , it still says the same error ."

        There were no replies when I started composing my response. My post was not related to Athanasius' post nor your 'hey it says "permission denied "'.

        "i was hoping is there any command that brings us to the current directory ?"

        That would be chdir — follow the link I posted above.

        "and if anyone can please state what could be the reason for permission deniale"

        That would depend on your OS. On *nix, it usually means you don't have write access to either the directory or the specific file.

        Your questions suggest you're unfamiliar with the OS you're working on. I'd recommend seeking advice from the system administrator.

        -- Ken

        #!/usr/bin/perl -- use strict; use warnings; Main( @ARGV ); exit( 0 ); sub Fudge { use Errno(); join qq/\n/, "Error @_", map { " $_" } int( $! ) . q/ / . $!, int( $^E ) . q/ / . $^E, grep( { $!{$_} } keys %! ), q/ /; } sub Main { for my $unfile ( 'NUL', './..', 'XYZQQQQQQQQQ', ){ unlink $unfile or warn Fudge( $unfile ); } } __END__ Error NUL 22 Invalid argument 87 The parameter is incorrect EMARCH_ENC_I17_IMM41a_VAL_POS_X EMR_SETTEXTALIGN EVENT_SYSTEM_MINIMIZESTART ERROR_BAD_COMMAND EINVAL at - line 20. Error ./.. 22 Invalid argument 5 Access is denied EMARCH_ENC_I17_IMM41a_VAL_POS_X EMR_SETTEXTALIGN EVENT_SYSTEM_MINIMIZESTART ERROR_BAD_COMMAND EINVAL at - line 20. Error XYZQQQQQQQQQ 2 No such file or directory 2 The system cannot find the file specified ETO_OPAQUE ERROR_LABEL_QUESTIONABLE EDS_RAWMODE EWX_REBOOT EC_QUERYWAITING EIMES_CANCELCOMPSTRINFOCUS ENOENT ELEMENT_STATUS_IMPEXP ENABLE_WRAP_AT_EOL_OUTPUT ES_RIGHT EV_RXFLAG ERROR_FILE_NOT_FOUND EVENTLOG_WARNING_TYPE EVENPARITY ENOFILE ESB_DISABLE_RTDN EMARCH_ENC_I17_IMM41c_INST_WORD_X EEInfoNextRecordsMissing ES_DISPLAY_REQUIRED ESB_DISABLE_RIGHT EVENT_MODIFY_STATE EMR_POLYBEZIER ENABLE_LINE_INPUT EVENT_SYSTEM_ALERT EXCEPTION_UNWINDING EC_RIGHTMARGIN EVENTLOG_END_PAIRED_EVENT EXTEND_IEPORT ExceptionNestedException ESB_DISABLE_DOWN EVENTLOG_SEEK_READ at - line 20.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1041726]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2023-12-11 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (41 votes). Check out past polls.

    Notices?