Situation:
Numerous sub-folders with random folder names containing several files with random names. Some I want to retain, others can be deleted.
Goal:
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.
Example; starting:
- parent1
- sub1
- random1.exe
- random2.pdf
- random3.txt
- sub2
- random4.exe
- random5.avi
- random6.log
- random7.jpg
- sub1
End result:
- parent2
- results-log.log
- random1.exe
- random2.pdf
- random4.exe
- random5.avi
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
%%G
correct? 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
move
or something else, and what's the/B
parameter?/y
is the only one I know of formove
.
Hopefully that's enough info, can edit as needed for more info.