[英]How to remove the first and last character from a file using batch script?
[英]remove last n characters of a file using batch
我的一个文件夹中有大约500个文件。 我正在尝试使用批处理“ for /r %i in (*) do type 4KB file.txt >> %i
将4KB数据(存储为文件)连接到所有文件, for /r %i in (*) do type 4KB file.txt >> %i
现在我希望他们恢复原始状态。 几乎没有文件在14GB左右。 尝试阅读时,打开它需要很多时间。
请让我知道如何将它们恢复为原始状态。
首先,此任务的难度取决于您附加到文件的实际字符串。
Get-ChildItem [your path here] | ForEach-Object {
$TempVar = Get-Content $_ | Select-string -Exclude "Something that uniquely matches the string you want to remove"
$TempVar | Set-Content $_ }
或者:
Get-ChildItem [your path here] | ForEach-Object {
$Length = ($_.ToCharArray) - 4096 #As you have 4KB, exactly?
$Newfile = ($_.ToCharArray() | Select -first $Length) -join ""
$NewFile | Set-content $_
}
两次尝试都被认为是有害的,因为这可能会影响编码,文件结构等-我只是没有足够的时间进行检查。 如果文件很重要,最好备份它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.