How can I check if a file exists in Perl?

前端 未结 8 2094
忘掉有多难
忘掉有多难 2020-12-01 02:28

I have a relative path

   $base_path = \"input/myMock.TGZ\";

myMock.TGZ is the file name located in input folder. The filenam

相关标签:
8条回答
  • 2020-12-01 03:09

    Use the below code. Here -f checks, it's a file or not:

    print "File $base_path is exists!\n" if -f $base_path;
    

    and enjoy

    0 讨论(0)
  • 2020-12-01 03:16
    if (-e $base_path)
    { 
     # code
    }
    

    -e is the 'existence' operator in Perl.

    You can check permissions and other attributes using the code on this page.

    0 讨论(0)
提交回复
热议问题