标题: 【已解决】【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
- <# :
- cls&echo off&cd /d "%~dp0"&rem 编码ANSI
- powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
- pause
- exit
- #>
- $csvfile=".\记录.csv";
- if(-not (test-path -literal $csvfile)){write-host ('"'+$csvfile+'" 未找到');exit;}
-
- $enc=[Text.Encoding]::GetEncoding('UTF-8');
- $text=[IO.File]::ReadAllLines($csvfile, $enc);
- if($text.count -ge 3){
- $arr=@($text[1..($text.count -1)]|sort {$_.split(',')[6]} -Descending);
- $newtext=$text[0]+"`r`n"+($arr -join "`r`n");
- [IO.File]::WriteAllText($csvfile, $newtext, $enc);
- }
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |