| 1. |
Solve : Batch problem. (xcopy)? |
|
Answer» I wrote a short batch file in windows xp, who needs to copy from one directory to the other and from the other one to this one (updating all the filles from one to another): maby it can't be solved. Of course it can be solved. You need to use an editor that can save the exclude file with Unicode encoding. (Notepad works fine). With all the select and copy from the character map and the pasting into Notepad, it is a painstakingly slow process but given enough time and effort this can be done. Hint: You can select all the characters in sequence for a single file from the character map and then copy the entire string to the clipboard for pasting into notepad. This way you build the exclude file line by line instead of character by character. Note: Test just one excluded file and use the XCOPY /L switch. This will list out the files that would be copied but no actual file copying takes place. Remove the /L switch when you're ready for the real thing. Good luck. I tried it (the unicode save) and it worked. But haw can i save a text file (with this unicode thing) using c#? Is there a function that saves a file and get's arguments? ect. (because im writing to the exclude files using c#)I'm not a C# programmer, but it looks suspiciously like VB.Net This may help. Check out Write a Text File (Example 2). Thanks!! Quote from: Sidewinder on July 11, 2010, 11:01:27 AM I'm not a C# programmer, but it looks suspiciously like VB.Net C# is nothing like VB.NET Syntax wise, only framework-wise. Anyway, if I understand the requirement, is the intention to open an ASCII file and save it as a Unicode? Because that's pretty easy. The sample referenced looks old- it doesn't use the now recommended "using" construct, and instead wraps everything in a try...catch...finally. Anyway, I took this as a small project and came up with a small program that simply opens a file using ASCII encoding, and WRITES it to another file that it opens/creates for Unicode. Code: [Select]using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace writetest { class Program { //note, I had to wrap the following constant in order to prevent the post from looking huge horizontally private const string helptext = "ASC2UNC help summary\n\nSYNTAX:\nASC2UNC <sourcefile> <destfile> [/a]\n\nASC2UNC opens the source file (using ASCII encoding) and directly copies the stream to the destination file (using unicode). of /A os specified, the destination file is opened for appending."; static void showhelp() { Console.WriteLine(helptext); } static void Main(string[] args) { //takes two arguments: args[0] is the source filename, args[1] is the destination filename. if (args.Length < 2) { Console.WriteLine("Error: Insufficient number of arguments."); showhelp(); return; } String sourcefile = args[0]; String destfile = args[1]; if (!Path.IsPathRooted(sourcefile)) sourcefile = Path.Combine(Environment.CurrentDirectory, sourcefile); if (!Path.IsPathRooted(destfile)) destfile = Path.Combine(Environment.CurrentDirectory, destfile); bool DoAppend = args.ToList().Exists((w) =>(w.Equals("/A", StringComparison.OrdinalIgnoreCase) || w.Equals("-A", StringComparison.OrdinalIgnoreCase))); try { using (StreamReader Ascinput = new StreamReader(sourcefile, Encoding.ASCII)) { using (StreamWriter Uncoutput = new StreamWriter(destfile, DoAppend, Encoding.Unicode)) { Uncoutput.Write(Ascinput.ReadToEnd()); } } } catch (IOException e) { Console.WriteLine("Exception:" + e.Message); } } } } to test, I created a sample text file in Notepad and saved it using ASCII encoding. I then used the program and created a file, "unicode.txt" which, while I was able to use "type" and other PROGRAMS to view the file just fine, was twice the size of the ASCII file I created it from (suggesting unicode was in fact properly used). Of course I really have no idea wether this is even close to what is desired, but I would imagine it's closer then the sample. Also if the ability to go the other way is required, it shouldn't be too DIFFICULT. One could simply store the Encoding enumeration values in variables and change them if you find specific switches. ... oh yeah and sorry about the lambda expression... I remember how confusing those were for me but now they are second nature. |
|