Need To Do Fancy Windows File Manipulation

Click For Summary

Discussion Overview

The discussion revolves around file manipulation in Windows, specifically focusing on deleting .jpg files from multiple folders while retaining .mp4 files. Participants explore various methods using command line instructions, PowerShell, and Windows Explorer, addressing concerns about data loss and providing alternative approaches.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant seeks a command to delete .jpg files from numerous folders without manual intervention.
  • Another participant shares a link to a PowerShell solution for deleting files with specific extensions.
  • A participant warns about the risks of using the erase command without a safety net, suggesting the use of the /p option to confirm deletions.
  • Alternative methods are proposed, including using Windows Explorer to search for and delete .jpg files.
  • One participant suggests using robocopy to mirror directories and exclude .jpg files.
  • Another participant recommends moving .jpg files to a different folder instead of deleting them, citing the benefits of retaining the files for potential future use.
  • A later reply confirms successful execution of a suggested method, detailing the process of resizing and moving files, and expressing surprise at the amount of space recovered.

Areas of Agreement / Disagreement

Participants present multiple competing views on how to handle the deletion of .jpg files, with no consensus on a single method. Concerns about data loss and the safety of different approaches are also highlighted.

Contextual Notes

Participants express varying levels of caution regarding file deletion, emphasizing the importance of backups and the potential for unintended data loss. Some methods discussed may depend on specific user settings or configurations in Windows.

Who May Find This Useful

This discussion may be useful for users looking to manage large quantities of files in Windows, particularly those interested in command line operations, PowerShell scripting, or file organization strategies.

Hornbein
Gold Member
Messages
3,791
Reaction score
3,063
I have about one hundred folders. Each folder has both .jpg and .mp4 files. I want to delete all the .jpgs but not the .mp4s. I don't want to do each folder by hand. Does anyone know the Windows/DOS command that will do this. Just moving the files depending on file type is enough.
 
Computer science news on Phys.org
Please be very careful with this, there is no safety net to catch you.

If all the 100 folders are inside folder x then open a command window and CD into folder x and then

erase /p /s *.jpg

That /p is going to prompt you to ask whether you want each file erased or not. I would suggest looking carefully at the name of the file it is about to erase and answering no to that question again and again and again until it is done. If every one of those file names was correct and it didn't end up asking you if you wanted to erase a very important file that you wanted to keep then you can do

erase /s *.jpg

and let it go.

All this is based on reading

https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/erase

The /s will have it look into the x folder, erase all jpg files there and then go into every folder inside x and do the same and go into every folder in every folder inside x, etc.

Ah, there is another way.

Windows Explorer is what you may use when you are trying to find files. You can use that to move to your x folder and then use the search box that is in the upper right corner to look for all jpg files in x and below x. That will take a while to complete. That should show you a list of every jpg file in those folders. Then you can carefully look through all the buttons across the top of the window and find a button that will Select All of those search results. That should highlight all the 100 plus jpg files. Then more looking through the buttons and you should find a red X with a Delete label under it. Tapping on that X should move all those highlighted file names to the Recycle Bin. (There are settings to make anything deleted to be instantly permanently deleted, presumably you have not set that. There are also things like if you do this from an inserted thumb drive that the deleted files do not go to the recycle bin on the thumb drive, because there isn't one, presumably you are not doing this from a thumb drive. After all those cautions... (Can you tell I don't trust not losing important files?) Then you are free to close Windows Explorer, open the Recycle Bin, see that all the appropriate files are there and then empty the bin.

Please post a message when you are done and let everyone know how it worked for you
 
Last edited:
  • Like
Likes   Reactions: jedishrfu
Can you use robocopy?

robocopy c:\old c:\new /mir
robocopy c:\old c:\new /s *.jpg
 
Rather than a delete, I suggest a move operation so that the files are not lost. That way if you ever need them again, you have them, but they are in a different folder so no longer in the way.

The Windows powershell move command will do this. Here's a good place in the Microsoft Learning Center to get the syntax and see an example:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/move-item?view=powershell-7.3

You want to look for Example 4. Here's part of it
1669437917199.png
 
  • Like
Likes   Reactions: Wrichik Basu
That worked like a charm. I had well over ten thousand photos each from three to nine megabytes in size. I had them all backed up on an external hard drive. I never look at them. I resized them all, reducing to about 4% of the size of the original, moved the original jpgs to another directory with Powershell, then deleted that directory. Recovered about 60 gigabytes.

Surprising to me is that I still have 60 gig of mp4 videos. I would never have imagined it was anywhere near that. I seldom make them, or at least so I thought. I never watch them. I guess they will be next to get the axe when the SSD fills up again.
 
  • Like
Likes   Reactions: jack action and phinds

Similar threads

  • · Replies 16 ·
Replies
16
Views
5K
  • · Replies 35 ·
2
Replies
35
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
6
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
Replies
3
Views
5K