Delete everything but picture files from a directory structure?


  1. Posts : 194
    Win 7,8.1 ,10
       #1

    Delete everything but picture files from a directory structure?


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


  2. Posts : 15,441
    Windows10
       #2

    ZippyDSMlee said:
    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.
      My Computer


  3. Posts : 194
    Win 7,8.1 ,10
    Thread Starter
       #3

    cereberus said:
    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
      My Computer


  4. Posts : 42,734
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #4

    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!
      My Computers


  5. Posts : 757
    Host W8.0 x64 Guest W10 x86
       #5

    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 http://www.autohotkey.com


    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 forums 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.
      My Computer


  6. Posts : 194
    Win 7,8.1 ,10
    Thread Starter
       #6

    MilesAhead said:
    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 http://www.autohotkey.com


    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 forums 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).
      My Computer


  7. Posts : 757
    Host W8.0 x64 Guest W10 x86
       #7

    ZippyDSMlee said:
    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.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 12:03.
Find Us




Windows 10 Forums