Using Perl to rename files in a directory

前端 未结 4 385
故里飘歌
故里飘歌 2021-01-12 10:56

I\'d like to take a directory and for all email (*.msg) files, remove the \'RE \' at the beginning. I have the following code but the rename fails.

opendir(D         


        
4条回答
  •  余生分开走
    2021-01-12 11:04

    You seem to be assuming glob-like behavior rather than than readdir-like behavior.

    The underlying readdir system call returns just the filenames within the directory, and will include two entries . and ... This carries through to the readdir function in Perl, just to give a bit more detail on mu's answer.

    Alternately, there's not much point to using readdir if you're collecting all the results in an array anyways.

    @files = glob('emails/*');
    

提交回复
热议问题