简体   繁体   中英

Windows Batch File to Delete Audio Files, with Length Requirement

and thank you for any help. I have tried searching for an example on how to accomplish the following, but haven't found anything. Any help would be appreciated as I have no experience in creating a BAT file!

I have a third party program that records audio, and generates an .mp3 file from it. Every 24 hours, it generates a new folder, and begins the process all over again. The problem is, even the slightest bit of sound will generate an .mp3 file. I am left with thousands of .mp3 files that are less than 1 second. I would like to delete all audio files in all of the subdirectories with a length of less than 2 seconds. How can I go about this, and is a BAT file the correct way to accomplish this? The manual way of sorting the files in the many, many directories is a very time consuming process as 20 - 30 days of files will be generated before I am able to go through them.

For a GUI solution: The shareware uncrippled Total Commander can list a full directory tree (control B) and sort by filesize (control F6) and can also display only MP3 files if needed.

This task would just need you to mark the filesizes less than x MBytes in a single pane and then you can delete them all at once.

Another solution is available with a batch file to delete MP3 files of 2.999 seconds or below:
- change [210] to [10] to delete files up to 1.999 seconds.

Download Mediainfo command line version from SourceForge
Change the path to the executable in line 2 below
Launch this batch file in the main folder of the tree of files
If the del commands you see on the screen are right then remove the echo and run it again to delete the files.

@echo off
set "exe=c:\Util\MediaInfo\MediaInfo.exe"
for /r %%a in (*.mp3) do (
"%exe%" -f "%%a" |find "Duration" | findstr /r ": 00:00:0[210]" >nul && echo del "%%a"
)
pause

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM