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

Script to copy files where filename contains a plus sign is creating folder with file within folder, instead of just copying file directly. During this copy files containing + in filename creates extra directory (same name as US source file) with US source file within. E.g FileName: en+DIMENSIONS_HELP+base.xlf On copy creates: en+DIMENSIONS_HELP+base.xlf/en+DIMENSIONS_HELP+base.xlf Has anyone see this issue before? As alternative tried zipping file and copying zip file to new location but on extract of zip file also creates extra folder structure. Any solutions?
  • Comment on Any issue with copy of file where filename contains + sign?

Replies are listed 'Best First'.
Re: Any issue with copy of file where filename contains + sign?
by Corion (Patriarch) on Apr 09, 2010 at 13:42 UTC

    How is this a Perl problem?

    Hint: You don't show any code. If you showed a small, self-contained (10-20 lines) program that exhibits the problem you mention, we can likely show you where the error stems from. Often, by reducing your program to such a small testcase, you will find that you find the error yourself.

      I tried this copy commands via command line and worked correct. Via perl script I am getting a problem. Similarly for zip of files, works from command line, via perl script see the problem. if ($filename_new =~ m/\+/ ) { $filename_new = $bugfixzip; my $bugfixzip = $SOURCE_DIR."/"."bugfixfiles.zip"; print "Zipping files with + sign in filename\n"; system("zip ${bugfixzip} ${filename_new}"); print "copy $bugfixzip","$WORK_DIR/$project/$version/$lang/us_source/$bugfixzip\n"; copy ("$bugfixzip","$WORK_DIR/$project/$version/$lang/us_source/bugfixfiles.zip"); system("unzip $WORK_DIR/$project/$version/$lang/us_source/bugfixfiles.zip $WORK_DIR/$project/$version/$lang/us_source/"); }

        If you can't read your post, what makes you think we can?

        The preview is not there to make your life harder, but to give you a chance to fix broken formatting like the post above. As it says when you submitted that:
        If something looked unlike you expected it to you might need to check out Writeup Formatting Tips.

        If you want help, don't be lazy!

Re: Any issue with copy of file where filename contains + sign?
by ikegami (Patriarch) on Apr 09, 2010 at 17:53 UTC

    + is special to copy. It's used to tell copy to concatenate files.

    copy a+b c

    Quote the file name.

    copy "a+b" c

    During this copy files containing + in filename creates extra directory

    copy doesn't create directories.

      thanks for your reply. Are you saying that it is possible to copy files with + in filename without script creating extra directory in perl?

        Sure thing. File::Copy's copy does not treat "+" specially. And like most copy utilities, it doesn't create directories. (See mkdir and File::Path's mkpath if you need to create directories.)