使用Windows SORT命令进行就地排序 [英] Inplace sorting using Windows SORT Command

查看:645
本文介绍了使用Windows SORT命令进行就地排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Window 7的SORT命令对.csv文件进行排序,当我将结果输出到单独的csv文件时,该命令可以正常工作,但是我需要进行就地排序.

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.

代码在下面.

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();

以上代码将整个源文件清空.如果我做/C排序文件名,则不对文件排序.但是,如果源和目的地不同,则上面的代码可以正常工作.有人可以就地排序吗?

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

这篇关于使用Windows SORT命令进行就地排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆