1

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

1 Answers1

0

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}
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • Thank you. Works fine if using {$_ -eq 0} but only checks if one of the first 4 bytes is zero. Though that should be enough since there shouldn't be any leading zero bytes in the file. – user3299411 Feb 12 '14 at 03:18
  • You can easily make that `4` a variable e.g. `Get-Content foo.xml -enc byte -TotalCOunt $numBytes`. – Keith Hill Feb 12 '14 at 17:14