I am using Window 7’s SORT command to SORT a .csv file , When i output the results to a separate csv file the command works fine but i need to do inplace sorting.
The code is below.
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo= new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C sort C:\\Users\\fFayyaz\\Desktop\\12.csv > C:\\Users\\fFayyaz\\Desktop\\12.csv";
process.StartInfo = startInfo;
process.Start();
The above code empty whole source file . If i do /C sort filename it does not sort the file. But if source and destination are different above code works perfectly.Can somebody help with inplace sorting.
You can’t do in place sorting. You can simulate the effect by renaming the file to sort in a temp file and then launch the command to convert the renamed file into the old file name. Add dome transactionality to check if there is some error, copy back the old file with the original name.
Note : We cannot do inplace sorting and source file is empty because the command clears the output file before writing to it and as output and input files are same it looses the data