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

i use Suse Linux.

i wanna copy all files listed in file:list4, but they are Chinese files with Chinese file names.

variable $1 and $2 are direcory names, and $3 is the Chinese file name.

almost half of the files are copied successfully, with the code as the follws :

system("cp $spath$1/$2/$3 $tpath$3");

however, if there are space,quotes, brackets, or dash lines in the file names, then the above code won't work.

if i add double quotes to variable $3, like :

system("cp $spath$1/$2/"$3" $tpath$3");

the syntax error messages are :

(Missing operator before $3?)

(Missing operator before " $tpath"?)

so,execution aborted due to compilation errors.

is there anyway to copy files with Chinese names and special characters in Suse Linux?

Thanks for any advise in advance !

-- Anne

<code> #!/usr/bin/perl use Cwd; use strict; use utf8; my $tpath="/tmp/ttmp/"; my $spath="/opt/myfirstbank/uploadDir/"; open(F,"list4") or die "Cannot open list2. $!\n"; while (<F>) { $_=~/^(.*?)\/(.*?)\/(.*?)\s/; system("print $1/$2\n"); system("cp $spath$1/$2/"$3" $tpath$3"); } close F;
  • Comment on How to copy files with Chinese names and special characters in Suse Linux?
  • Download Code

Replies are listed 'Best First'.
Re: How to copy files with Chinese names and special characters in Suse Linux?
by moritz (Cardinal) on Jun 16, 2011 at 08:52 UTC
      Thanks for answering this question. But, that doesn't work, and the message is that "there is no such directory or file" when there is whitespace in file name. Does anyone has any other ideas ? Thanks for help in advance! - Anne
        Do the files and directories actually exist on your system?

        Try removing the use utf8;, since path names are byte strings on Linux and Unix systems.