Board logo

标题: 【已解决】【30元红包】批处理csv文件降序排 [打印本页]

作者: linfeng_321    时间: 2022-3-30 16:01     标题: 【已解决】【30元红包】批处理csv文件降序排

本帖最后由 linfeng_321 于 2022-3-30 18:05 编辑

根目录\文档\记录.csv
批处理脚本:放根目录
------------------------------------------------
原始:记录.csv,文件内容如下:
---------------
"本机当前用户名","本机IP地址","编号","名称","作者","版本","开始时间","结束时间","当前状态","制作次数"
"123","192.168.1.97","1222211249","名称6","老六","9","2022-03-30 15:10:14","","制作中","1"
"123","192.168.1.97","1222211248","名称5","老五","4","2022-03-24 15:20:59","","制作中","5"
"123","192.168.1.97","1222211247","名称4","老四","1","2022-03-13 15:20:59","","制作中","2"
"123","192.168.1.97","1222211246","名称3","老三","7","2022-03-19 15:20:59","","制作中","0"
"123","192.168.1.97","1222211245","名称2","老二","2","2022-03-30 15:25:58","","制作中","1"
"123","192.168.1.97","1222211244","名称1","老大","3","2022-03-21 13:20:51","","制作中","9"
------------------------------------------------
以“开始时间”降序排
------------------------------------------------
修改后:记录.csv,文件内容如下:
---------------
"本机当前用户名","本机IP地址","编号","名称","作者","版本","开始时间","结束时间","当前状态","制作次数"
"123","192.168.1.97","1222211245","名称2","老二","2","2022-03-30 15:25:58","","制作中","1"
"123","192.168.1.97","1222211249","名称6","老六","9","2022-03-30 15:10:14","","制作中","1"
"123","192.168.1.97","1222211248","名称5","老五","4","2022-03-24 15:20:59","","制作中","5"
"123","192.168.1.97","1222211244","名称1","老大","3","2022-03-21 13:20:51","","制作中","9"
"123","192.168.1.97","1222211246","名称3","老三","7","2022-03-19 15:20:59","","制作中","0"
"123","192.168.1.97","1222211247","名称4","老四","1","2022-03-13 15:20:59","","制作中","2"
作者: zaqmlp    时间: 2022-3-30 17:58

  1. <# :
  2. cls&echo off&cd /d "%~dp0"&rem 编码ANSI
  3. powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
  4. pause
  5. exit
  6. #>
  7. $csvfile=".\记录.csv";
  8. if(-not (test-path -literal $csvfile)){write-host ('"'+$csvfile+'" 未找到');exit;}
  9. $enc=[Text.Encoding]::GetEncoding('UTF-8');
  10. $text=[IO.File]::ReadAllLines($csvfile, $enc);
  11. if($text.count -ge 3){
  12.     $arr=@($text[1..($text.count -1)]|sort {$_.split(',')[6]} -Descending);
  13.     $newtext=$text[0]+"`r`n"+($arr -join "`r`n");
  14.     [IO.File]::WriteAllText($csvfile, $newtext, $enc);
  15. }
复制代码





欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2