python文本去重复_批处理去除文本的重复行并保留空行 - BAT求助&讨论 - 批处理之家 批处理_BAT脚本_PowerShell_VBS_CMD_DOS_Perl_Python - Powe...

@echo off

rem writen by pcl_test

rem bat/ps1通用

rem 测试前先备份源文件或文件夹

type "%~f0"|powershell -noprofile -sta "-"

>nul ping /n 6 0&exit

#>

$global:files=@();

$ListFile={

$global:files=@();

$button2.Enabled = $false;

$button2.Text = '获取文件中';

if($radioButton1.Checked){

$global:files=FileDialog;

}else{

$global:files=FolderDialog;

}

$textBox2.Text=$files.Count;

if($files.Count){

$textBox3.Text=$files -join "`r`n";

$textBox3.Enabled = $true;

}else{

$textBox3.Text='测试前先备份源文件或文件夹';

$textBox3.Enabled = $false;

}

$button2.Text = '选择文件或文件夹';

$button2.Enabled = $true;

}

$EditFile={

switch($comboBox1.Text)

{

'UTF-8'{$outenc=[Text.Encoding]::UTF8;}

'Unicode(LittleEndian)'{$outenc=[Text.Encoding]::Unicode;}

'Unicode(BigEndian)'{$outenc=[Text.Encoding]::BigEndianUnicode;}

Default{$outenc=[Text.Encoding]::Default;}

}

if($files.Count){

$button1.Enabled = $false;

$button2.Enabled = $false;

$button1.Text = '处理中';

for($i=0;$i -lt $files.Count;$i++)

{

$tmp=ClearExtra $files[$i];

OutFile $files[$i] $tmp $outenc;

if([int]$textBox2.Text -gt 0){$textBox2.Text=[int]$textBox2.Text-1;}

[System.Windows.Forms.Application]::DoEvents();

write-host $files[$i];

}

$button1.Text = '执行';

$button1.Enabled = $true;

$button2.Enabled = $true;

[void][System.Windows.Forms.MessageBox]::Show('Done','提示');

}

}

function CheckExt

{

$ext=@();

if(($textBox1.Text.Trim() -eq '') -or ($textBox1.Text.Trim() -notmatch '^\*\.[a-z\d]+(;\*\.[a-z\d]+)*$')){

[void][System.Windows.Forms.MessageBox]::Show('指定扩展名不能为空或非法');

}else{

$ext=($textBox1.Text -replace '\s*','').split(';',[StringSplitOptions]::RemoveEmptyEntries);

}

return ,$ext;

}

function FolderDialog

{

$filelist=@();

$ext=CheckExt;

if($ext.Count){

$fbd = New-Object System.Windows.Forms.FolderBrowserDialog;

$fbd.RootFolder = 'MyComputer';

$fbd.ShowNewFolderButton = $false;

$Show = $fbd.ShowDialog();

If ($Show -eq 'OK'){

$fd=$fbd.SelectedPath;

dir $fd -r|?{($_ -is [System.IO.FileInfo]) -and ($ext -contains ('*'+$_.Extension))}|%{

$filelist+=(,$_.FullName);

}

}

}

return ,$filelist;

}

function FileDialog

{

$filelist=@();

$ext=CheckExt;

if($ext.Count){

$ofd = New-Object Windows.Forms.OpenFileDialog;

$ofd.InitialDi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值