Numerous sub-folders with random folder names containing several files with random names. Some I want to retain, others can be deleted.
Move the files with extensions: *.exe *.pdf *.avi or other specified extentions out of the subfolders and into a common separate folder without recreating the previous folder structure. So that I have one folder with just the files I want, leaving behind any other file types. Then log the subfolder directory names (results-log.log) and delete the subfolders and everything left in them.
So I've searched around for other answers and it looks like I need some sort of FOR loop, but I don't understand enough of how that works with parameters to do what I need. Moving pdf files to parent folder from subfolder with variable names is one example I looked at, and I looked over the suggested reading, but I totally don't get how the parameters and variables work. Especially where I need to cover several file types.
So far I'm looking at something like this:
@ECHO OFF SETLOCAL EnableExtensions set "_parent=c:\logs\cache\" set "_dest=c:\archive\" for /D /r %%G in ("%_parent%\*") do ( if exist "%%~G\*.pdf" ( echo move /B "%%~G\*.pdf" "%_dest%\" ) else ( echo nothing to copy "%%~G\*.pdf" "%_parent%\" ) )
- Line 3 I believe that sets "c:\logs\cache\" as the parent folder, so in my example about that would equal "parent1"
- Line 4 should set the destination for example folder "parent2" as "c:\archive"
- Line 5 is
%%Gcorrect? Does it matter what the letter is?
- Line 6 how do I specify the other file extensions I want to look for?
- Line 7 do I want to use
moveor something else, and what's the
/yis the only one I know of for
Hopefully that's enough info, can edit as needed for more info.