I search "windows 7 64 bit batch cmd move multiple files from multiple subdirectories based on extension 100mb max limit renaming from original deleting empty source subdirectories"
========================================================
AI Overview
Use this batch script to recursively process your files. It matches your target extension, checks if the file is ≤ 100 MB, renames the file by prefixing its parent folder name to prevent duplicates, moves it to the destination, and deletes the source folders if they are empty. [
1,
2,
3,
4,
5]
cmd
<span data-copy-service-computed-style="font-family: monospace; font-size: 14px; font-weight: 400; margin: 0px; text-decoration: none; border-bottom: 0px rgb(0, 29, 53);">@echo off<br>setlocal enabledelayedexpansion<br><br>:: 1. SET YOUR VARIABLES BELOW<br>set "SourceDir=C:\Path\To\Source"<br>set "DestDir=C:\Path\To\Destination"<br>set "Ext=txt"<br><br>:: 2. CREATE DESTINATION FOLDER<br>if not exist "%DestDir%" mkdir "%DestDir%"<br><br>:: 3. PROCESS FILES<br>cd /d "%SourceDir%"<br>for /r %%F in (*.%Ext%) do (<br> if "%%~aF" neq "" (<br> if %%~zF leq 104857600 (<br> for %%I in ("%%~dpF.") do set "ParentName=%%~nxI"<br> move "%%F" "%DestDir%\!ParentName!_%%~nxF"<br> )<br> )<br>)<br><br>:: 4. REMOVE EMPTY DIRECTORIES (Bottom-Up)<br>for /f "tokens=* delims=" %%D in ('dir /ad /b /s ^| sort /r') do (<br> rd "%%D" 2>nul<br>)<br><br>echo Done!<br>pause<br></span>
Use code with caution.
How to use it:
- Open Notepad.
- Paste the code block above into the document.
- Modify the variables in section 1 (SourceDir, DestDir, and Ext) with your exact directory paths and the file extension you want to isolate. (Note: The size is set in bytes: 100MB = 104857600bytes).
- Click File > Save As and name it something like MoveAndClean.bat.
- Set the "Save as type" dropdown to All Files and save it.
- Double-click the .bat file to run it. [1, 2, 3, 4]
If you want, I can help you:
- Change the script to copy instead of move so you keep a backup.
- Filter by date (e.g., only move files older or newer than a specific date).
Let me know how you'd like to proceed!



6 sites
- How to rename multiple files in subfolders using Windows command prompt - DEV Community
Aug 28, 2021 — To rename files recursively in subfolders using the Windows command prompt, you can use the REN (rename) command: * **FOR /R %G IN...


DEV Community
- move cmd command - GeeksforGeeks
Oct 20, 2020 — move cmd command * [drive:][path]filename1 - Specifies the location and name of the file or files you want to move. * destination ...


GeeksforGeeks
- One-line batch script to delete empty directories
Apr 17, 2008 — Raymond Chen Show more You don't need a whole 260KB program to do it. This batch file does the trick just fine: for /f "usebackq" ...


Microsoft Dev Blogs
Show all
AI can make mistakes, so double-check responses
----------------------------------------------------------------------------------------------------------------------------------------------------------
========================================================================================
AI Mode
To move files from multiple subdirectories based on extension, filter by size, rename them to avoid conflicts, and delete empty folders, use the script below.
Windows Batch cannot natively read file sizes in megabytes easily, so the script converts 100MB into bytes (104,857,600 bytes).
The Batch Script
Create a text file, paste this code, and save it as move_files.bat. [1, 2]
<span>@echo off<br>setlocal enabledelayedexpansion<br><br>:: --- CONFIGURATION ---<br>set "source_dir=C:\path\to\source"<br>set "dest_dir=C:\path\to\destination"<br>set "ext=*.txt"<br>set /a max_size=104857600<br>:: ---------------------<br><br>echo Processing files...<br><br>:: Loop through all subdirectories and match extension<br>for /r "%source_dir%" %%F in (%ext%) do (<br> if exist "%%F" (<br> :: Check file size limit<br> if %%~zF LSS %max_size% (<br> set "filename=%%~nxF"<br> set "filepath=%%~fF"<br> <br> :: Check for duplicate in destination<br> if exist "%dest_dir%\%%~nxF" (<br> set "count=1"<br> :loop<br> if exist "%dest_dir%\%%~nF_!count!%%~xF" (<br> set /a count+=1<br> goto loop<br> )<br> set "filename=%%~nF_!count!%%~xF"<br> )<br> <br> :: Move and rename the file<br> move "%%F" "%dest_dir%\!filename!" >nul<br> )<br> )<br>)<br><br>echo Cleaning up empty directories...<br><br>:: Delete empty source subdirectories<br>for /f "delims=" %%D in ('dir "%source_dir%" /ad /b /s ^| sort /r') do (<br> rd "%%D" 2>nul<br>)<br><br>echo Done!<br>pause<br></span>
How to Customize It
- source_dir: Change to your parent folder path.
- dest_dir: Change to your target folder path.
- ext: Change *.txt to your target extension (e.g., *.mp4, *.jpg).
- Renaming Logic: If image.jpg already exists in the destination, the script renames the incoming file to image_1.jpg, image_2.jpg, etc.
- Directory Cleanup: The sort /r command reverses the directory list. This ensures deepest subdirectories delete first, allowing parent folders to become empty and delete successfully.
Safety Warning
Always test Batch scripts on a small test folder with copies of your files before running them on your live data.
If you want to modify this script, let me know:
[1]
https://www.youtube.com
[2]
https://www.youtube.com