Question

I have two ways forward at the moment. Either would work but I'm not quite there with the batch programming yet. I sometimes get corrupt .xml files in a folder and need to delete such. When that happens the .xml file consist of only hex 00 00 00 00 00 ....

  1. If there is a .xml files that has more than x bytes leading binary zeros it should be deleted.

  2. Delete the .xml file with the oldest timestamp in a directory WHEN there are more than x .zip files in the same folder. When there is a corrupt xml in the directory the .zip files are stacking up instead of getting unpacked and deleted.

In Linux I Think I would have been able to fix this but in this Windows machine I would prefer to use only standard batch commands.

Edit: Powershell code would work for me too.

edit2: (fixed it myself with a bit of google help) certutil -dump %%f | find "00 00 00 00 00 00 00 00" && move %%f .\corrupt slow but works, will probably use the powershell solution below

Thank you for your help /Per

Was it helpful?

Solution

For finding XML files with leading 0 bytes, you could do something like this:

Get-Content foo.xml -Encoding Byte -TotalCount 4 | 
    Where {$_ -ne 0} | Foreach {'Xml is corrupt';break}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top