How to handle filenames with spaces?

前端 未结 7 808
后悔当初
后悔当初 2020-12-11 03:37

I use Perl on windows(Active Perl). I have a perl program to glob the files in current folder, and concatenate them all using dos copy command called from within using syste

7条回答
  •  没有蜡笔的小新
    2020-12-11 04:26

    Issues may arise when you're trying to access the variable $_ inside an inner block. The safest way, change:

    foreach (@files)
    

    to:

    foreach $file (@files)
    

    Then do the necessary changes on @args, and escape doublequotes to include them in the string..

    @args = ('copy' ,"/b ","\"$file\"","+","$outfile", "$outfile");
    ...
    @args = ('copy' ,"/b ","$outfile","+","\"$file\"", "$outfile");
    

提交回复
热议问题