[英]remove last n characters of a file using batch
I am having around 500 files in a folder. 我的一个文件夹中有大约500个文件。 I am trying to concatenate a 4KB data(stored as a file) to all the files using batch "
for /r %i in (*) do type 4KB file.txt >> %i
我正在尝试使用批处理“
for /r %i in (*) do type 4KB file.txt >> %i
将4KB数据(存储为文件)连接到所有文件, for /r %i in (*) do type 4KB file.txt >> %i
Now I want them to revert to orignal state. 现在我希望他们恢复原始状态。 Few files are around 14GB .
几乎没有文件在14GB左右。 While trying to read , it takes a lot of time to open.
尝试阅读时,打开它需要很多时间。
Please let me know how can I revert them back to original state. 请让我知道如何将它们恢复为原始状态。
First off, the difficulty of this task depends on the actual string you appended to the file. 首先,此任务的难度取决于您附加到文件的实际字符串。
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 $_ }
Alternatively: 或者:
Get-ChildItem [your path here] | ForEach-Object {
$Length = ($_.ToCharArray) - 4096 #As you have 4KB, exactly?
$Newfile = ($_.ToCharArray() | Select -first $Length) -join ""
$NewFile | Set-content $_
}
Both attempts can be considered harmful as this may affect encoding, file structure etc - I just don't have enough time to check on that. 两次尝试都被认为是有害的,因为这可能会影响编码,文件结构等-我只是没有足够的时间进行检查。 If the files are of any importance, better back them up.
如果文件很重要,最好备份它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.