-1

I have .blk and .blkx files in the same folders, of wich im trying to delete only the .blk file. Ive attempted examples found on this post as in del "\folder\*.blk" /s. I managed to get the chosen files deleted however the .blkx files were deleted too (other files werent so i assume its an issue with both the file having .blk in their extension).

How can i select only the .blk file?

Edit: I dont know why this post was marked a duplicate but the above pinned post does not resolve the problem (wich i already talked about not working)

FlareFlo
  • 1
  • 1
  • 2

1 Answers1

1

You must have SFNs (short filenames) enabled on that drive, and the .blkx extension is mapped to .blk in the short 8.3 filename. Because of this, and because wildcards match both long and short names, *.blk returns both .blk and blkx files. To distinguish between them you'll need to run a for loop, check the actual extension, and delete each .blk individually.

    for %%b in (*.blk) do @(if /I "%%~xb" == ".blk" echo del "%%~b")

Remove echo from the above to actually delete the .blk files.

To recurse into subdirectories (like del /s) use for /r instead of for.

The command is written as to be used in a batch file (per the question tag). To run it at a command prompt, instead, replace the double percents %%b with single ones %b.

dxiv
  • 16,984
  • 2
  • 27
  • 49