Location:
State:
Carrier
Country
Status

Delete everything but picture files from a directory structure?


Got an odd request, anyway to delete everything but picture files from a directory structure ?

Got an odd request, anyway to delete everything but picture files from a directory structure ?
Select all picture files in explorer, right click and select properties. Mark them as hidden, delete remaining files, and then unhide the files and remove hidden attribute.

You may have to do this by directory.

Select all picture files in explorer, right click and select properties. Mark them as hidden, delete remaining files, and then unhide the files and remove hidden attribute.

You may have to do this by directory.
Mmmmmm command line should be able to select a wild cards, tho I am unsure if you can string them together. Not sure if you can exempt this and delete that and keep folders but delete empty folders LOL

Hi, if this is only required once, and there aren't too many subfolders, a relatively simple way might be to use an image viewer. That automatically picks out all image files of types it supports.

View the folder in the image viewer, mark all as hidden. (Borrowing @Cerberus idea)
Delete the remainder in file explorer, unhide the images.

Repeat for all other folders.

I'm not sure if you're looking for a script to do this repeatedly.
If so, you could possibly do that with a viewer you can use from the command line e.g.
PictView - image viewers and converters
- but I can't see what the command line options are for that!

Code:
Loop, x:RootFolder*.*, 0,1 ;  x = drive letter - 1 = search subfolders {     if (A_LoopFileDir = A_WinDir)             continue      if A_LoopFileExt not in bmp,gif,jpg,png ; add other image extensions as needed       FileDelete, %A_LoopFileLongPath% }

You can download AutoHotkey free programming tools from


It may be a good idea to build in a sanity check to make sure the root folder does not contain the Windows folder or any folder with other files that should not be deleted. The code I pasted is just a quickie starting point. On the AHK site you can download tools including an IDE that can wrap the script and interpreter into an exe so that the program will run on machines that do not have AHK installed.


Enjoy

Edit: I added an If statement to skip to the next loop if the current folder is the Windows folder as example how it is done. The blog for autohotkey are populated with regular posters who enjoy helping people with their scripts. So just visit the "ask for help" forum there for enahancements.

Code:
Loop, x:RootFolder*.*, 0,1 ;  x = drive letter - 1 = search subfolders {     if (A_LoopFileDir = A_WinDir)             continue      if A_LoopFileExt not in bmp,gif,jpg,png ; add other image extensions as needed       FileDelete, %A_LoopFileLongPath% }

You can download AutoHotkey free programming tools from


It may be a good idea to build in a sanity check to make sure the root folder does not contain the Windows folder or any folder with other files that should not be deleted. The code I pasted is just a quickie starting point. On the AHK site you can download tools including an IDE that can wrap the script and interpreter into an exe so that the program will run on machines that do not have AHK installed.


Enjoy

Edit: I added an If statement to skip to the next loop if the current folder is the Windows folder as example how it is done. The blog for autohotkey are populated with regular posters who enjoy helping people with their scripts. So just visit the "ask for help" forum there for enahancements.
I'll give it a go, its mainly all just a recovery of a WinXP hard drive, they want the pictures on CD's(5 or 6 in all I think) of all things, so I need to pair it down some. I think one I get down to pictures I will remove the 0-10KB ones then check and make sure the rest are half viewable. Not having a bit of luck with picture repair programs or hex editing the headers. Blah oh well some are there and working at least.

Recovery of the hard drive on a USB hard drive(secondary documents and stuff they can get to if they want), plus pictures on CD plus all pictures on a DVD(dvds are nice I like dvds LOL).

I'll give it a go, its mainly all just a recovery of a WinXP hard drive, they want the pictures on CD's
...
Ah, in that case I feel much better. No worries about hosing a running system. AHK syntax can be weird on some of the older built in functions. But it can be great for doing file stuff simply. I wrote a utility to delete every index.dat file on the system drive in 7 lines of code. You could do the same thing with a command line batch but the AHK runs much smoother.

Delete everything but picture files from a directory structure?