xxcopy Unicode characters

I'm using xxcopy (the latest version that should support Unicode characters) in a Java application to make single file copies.  I'm using these switches:

Process p = Runtime.getRuntime().exec(new String[] { "cmd", "/c", "xxcopy", "\"" + sSource + "\"", "\"" + sDest + "\"", "/VL", "/C", "/H", "/K", "/YY", "/Q3"});
p.waitFor();
iRtn = p.exitValue();

But when the path being copied contains unicode characters, the copy fails with a return code of 34.

Does anyone know how to handle unicode characters with xxcopy?

jkavx
jkavxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gibu GeorgeChief Technology OfficerCommented:
see this link

http://www.xxcopy.com/xxgroup/m04/msg04879.htm

it says

"To tell the truth, this could possible be a bug (feature?)
of XXCOPY. Currently, XXCOPY does not support Unicode
based filenames"
0
jkavxAuthor Commented:
The latest version supports Unicode.
http://www.xxcopy.com/index.htm

Unicode support!!!
      Finally, the long awaited version with Unicode support is with us.
      XXCOPY no longer relies on the current setting of code page for
      its processing of files and directories for file-access operations.

      The most common method of invoking XXCOPY will likely remain to be
      the console window (the so-called DOS Box), that is restricted to
      8-bit (ANSI) character set (non-Unicode).  In order to specify
      Unicode based strings in file and directory names, one may use the
      /CF (command file) and /EX (exclusion list).  These files can be
      either in the traditional ANSI text format, or in the UTF-8 encoded
      Unicode text format with the presence of the Byte-Order Mark (BOM)
      at the beginning of the file.

      With the new /UT switch, you may force XXCOPY's output files to be
      in UTF-8 encoded Unicode text (for backward compatibility, the
      output file will be in 8-bit ANSI text).  The new /PW switch will
      help display the filename in Unicode in a dialog window when XXCOPY
      issues a user-prompt with a file/directory.

      For the most authoritative reference,

         http://en.wikipedia.org/wiki/UTF-8

      Please note that the new set of switch variations (/oUN, /oUA, /FUo,
      /CUF and /EUX for /oN, /oA, /Fo,/CF and /EX respectively --- introduced
      in v.2.97.0) are now rescinded.  The single switch, /UT (and /UT0 to
      cancel it) will uniformly control *ALL* of the output files rather
      than individually.


0
Mick BarryJava DeveloperCommented:
doesn't that say you need to use the /CF option and a command file
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

jkavxAuthor Commented:
I'm trying it, but get error 34:
String sCmdFile = "c:\\temp\\command.xcf";
File fileCmd = new File(sCmdFile);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream
   (fileCmd),"Unicode"));
String sCmd = "EF BB BF " + "\"" + sSource + "\"" + " \"" + sDest + "\"" + " /VL /C /H /K /YY /Q3";
bw.write(sCmd);
bw.close();
Process p = Runtime.getRuntime().exec(new String[] { "cmd", "/c", "xxcopy", "/CF:" + sCmdFile});
p.waitFor();
iRtn = p.exitValue();
0
jkavxAuthor Commented:
The OutputStreamWriter was the problem when instantiated with the "Unicode" argument.  This works:
String sCmdFile = "command.xcf";
File fileCmd = new File(sCmdFile);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileCmd)));
String sCmd = "\"" + sSource + "\"" + " \"" + sDest + "\"" + " /VL /C /H /K /YY /Q3";
bw.write(sCmd);
bw.close();
Process p = Runtime.getRuntime().exec(new String[] { "cmd", "/c", "xxcopy", "/CF:" + sCmdFile});
p.waitFor();
iRtn = p.exitValue();
0
jkavxAuthor Commented:
Not so easy...  The single copies of files with unicode characters in the path are wrong.  The copy does not put the file in the destination path.  It creates a new desintation path which is the destination path plus a portion of the file path being copied, starting from the unicode portion.  So:
"c:\blue\red\xxx\yyy\file.txt" copied to "c:\dest" creates "c:\dest\xxx\yyy\file.txt" where xxx are unicode characters.

It may be that this is what I'm missing:  "The [command file] can be either in the traditional ANSI text format, or the UTF-8 encoded Unicode text format with the presence of the Byte-Order Mark (BOM) at the beginning of the file."  I've tried putting "EF BB BF" at the start of the command file, which is my understanding of what the BOM should be.  But this just causes error 34.  

Is there some other way to mark the BOM at the beginning of the command file?
0
jkavxAuthor Commented:
It's a Java bug that files created with the OutputStreamWriter as below lack the BOM at the beginning of the file.  This is a fix:

File fileCmd = new File("command.xcf");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new
  FileOutputStream(fileCmd),"UTF8"));
byte[] bom = new byte[3];
bom[0] = (byte) 0xEF;
bom[1] = (byte) 0xBB;
bom[2] = (byte) 0xBF;
bw.write(new String(bom, "UTF-8"));
... write the rest of the file
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.