Jump to content
Sign in to follow this  
harrisms

Delete all MP3

Recommended Posts

harrisms

I have MP3s stored in random places throughout my computer. I would like to just delete all of these files. It's easier than trying to find them and move them. I tried using

FileDelete("C:\*\*\*\*.mp3")

But the wildcards don't work for directories apparently. So i have to tell it the exact path. But I don't really want to have to go through all that trouble of finding the paths. Can anybody help me here?

Share this post


Link to post
Share on other sites
Pain

With some minor changes this will work in AutoIt, I won't do it for you because you will have to do something yourself. It's very simple to translate it even without any or atleast very little knowledge of other langueges but if you got any problem feel free to post.

It will save a list with all mp3's in a textfile located at: C:\Test.txt

You can read from this file or change how to return the result like in a array or something.

This one is using WMI.

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

strFolderName = "C:\"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("C:\Test.txt")

Set colSubfolders = objWMIService.ExecQuery _
    ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
        & "Where AssocClass = Win32_Subdirectory " _
            & "ResultRole = PartComponent")

Set colFiles = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='" & strFolderName & "'} Where " _
        & "ResultClass = CIM_DataFile")

For Each objFile in colFiles
    If objFile.Extension = "mp3" Then
        objTextFile.WriteLine objFile.FileName 
    End If
Next

For Each objFolder in colSubfolders
    GetSubFolders strFolderName
Next

Sub GetSubFolders(strFolderName)

    Set colSubfolders2 = objWMIService.ExecQuery _
        ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
            & "Where AssocClass = Win32_Subdirectory " _
                & "ResultRole = PartComponent")

    For Each objFolder2 in colSubfolders2
        strFolderName = objFolder2.Name

    Set colFiles = objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_Directory.Name='" & strFolderName & "'} Where " _
            & "ResultClass = CIM_DataFile")

    For Each objFile in colFiles
        If objFile.Extension = "mp3" Then
            objTextFile.WriteLine objFile.FileName 
        End If
    Next

        GetSubFolders strFolderName
    Next
End Sub

Share this post


Link to post
Share on other sites
harrisms

What I was looking for was someone to give me an easy way to do it. Like the FileDelete("C:\...") command. I can just search my pc for all the .mp3's and find where they are. I was just looking for a simple way and that doesn't seem too simple.

Share this post


Link to post
Share on other sites
trancexx

What I was looking for was someone to give me an easy way to do it. Like the FileDelete("C:\...") command. I can just search my pc for all the .mp3's and find where they are. I was just looking for a simple way and that doesn't seem too simple.

I'm sure that Pain's new post will be "You welcome".

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Pain

For me it looks pretty simple, only a few lines and very easy to translate.

If you want to you can make it into a function and it will be as easy as FileDelete. :mellow:

Share this post


Link to post
Share on other sites
rudi

What I was looking for was someone to give me an easy way to do it. Like the FileDelete("C:\...") command. I can just search my pc for all the .mp3's and find where they are. I was just looking for a simple way and that doesn't seem too simple.

That's easyly possible with Windows' buildin commands in just one line. (which you could call from Autoit, of course)

But: Why should someone want to delete all his/her MP3 files from the whole hard disk? This sounds to me much, much more likely to be really bad "joke", basically: Some kind of a"FUNNY.EXE", to kill away someone other's full MP3 collection!

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
harrisms

Because I want to clean all the crap .mp3s off my hard drive. I have most moved or copied to my external. I have a ton of ringtones that are in mp3 format saved in random spots. I have mis-named mp3s and just want to start over. I figure if i deleted all of them then i could just bring in the ones from my external that have the right names and sorted correctly

Share this post


Link to post
Share on other sites
TehWhale

Easy as pie. Tested, works :mellow:

#include <Array.au3>

$Array = _FileListToArrayEx("C:\", "*.mp3", 1, "", True)
For $i=1 To $Array[0]
    FileDelete($Array[$i])
Next


Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    $sFilter = StringRegExpReplace($sFilter, '\s*;\s*', ';')
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder
    $sTFolder = $oFSO.GetSpecialFolder(2)
    Local $hOutFile = @TempDir & $oFSO.GetTempName
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead, $sHoldSplit
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC],8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        $sHoldSplit &= '"' & $sPath & $aSplit[$iCC] & '" '
    Next
    $sHoldSplit = StringTrimRight($sHoldSplit, 1)
    If $iRecurse Then
        RunWait(@Comspec & ' /c dir /b /s /a ' & $sHoldSplit & ' > "' & $hOutFile & '"', '', @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c dir /b /a ' & $sHoldSplit & ' /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE)
    EndIf
    $sRead &= FileRead($hOutFile)
    If Not FileExists($hOutFile) Then Return SetError(4, 4, '')
    FileDelete($hOutFile)
    If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft($aFSplit[$iCC], _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                    $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                Else
                    $sHold &= $aFSplit[$iCC] & Chr(1)
                EndIf
            Case 1
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') = 0 And _
                    StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') = 0 Then
                    If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                        $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                    Else
                        $sHold &= $aFSplit[$iCC] & Chr(1)
                    EndIf
                EndIf
            Case 2
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Or _
                    StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then
                    If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                        $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                    Else
                        $sHold &= $aFSplit[$iCC] & Chr(1)
                    EndIf
                EndIf
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc;==> _FileListToArrayEx
Edited by TehWhale

Share this post


Link to post
Share on other sites
muncherw

Why not just use windows search function for *.mp3 and then select all and delete from the results?


Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

Share this post


Link to post
Share on other sites
rudi

Because I want to clean all the crap .mp3s off my hard drive. I have most moved or copied to my external. I have a ton of ringtones that are in mp3 format saved in random spots. I have mis-named mp3s and just want to start over. I figure if i deleted all of them then i could just bring in the ones from my external that have the right names and sorted correctly

cmd box:

del /s c:\*.mp3

Regards, Rudi.

Edit: In case you should be planning to code a "panic button" to wipe out all MP3s for forensic reasons you have to know, that a simple delete won't help at all: The data itself remain on disk and can be retrieved quite easyly with even unexpensive tools. For such purpose you would need to physically overwrite, then delete the files.

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
UltraFine

Easy as pie. Tested, works :mellow:

#include <Array.au3>

$Array = _FileListToArrayEx("C:\", "*.mp3", 1, "", True)
For $i=1 To $Array[0]
    FileDelete($Array[$i])
Next


Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    $sFilter = StringRegExpReplace($sFilter, '\s*;\s*', ';')
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder
    $sTFolder = $oFSO.GetSpecialFolder(2)
    Local $hOutFile = @TempDir & $oFSO.GetTempName
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead, $sHoldSplit
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC],8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        $sHoldSplit &= '"' & $sPath & $aSplit[$iCC] & '" '
    Next
    $sHoldSplit = StringTrimRight($sHoldSplit, 1)
    If $iRecurse Then
        RunWait(@Comspec & ' /c dir /b /s /a ' & $sHoldSplit & ' > "' & $hOutFile & '"', '', @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c dir /b /a ' & $sHoldSplit & ' /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE)
    EndIf
    $sRead &= FileRead($hOutFile)
    If Not FileExists($hOutFile) Then Return SetError(4, 4, '')
    FileDelete($hOutFile)
    If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft($aFSplit[$iCC], _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                    $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                Else
                    $sHold &= $aFSplit[$iCC] & Chr(1)
                EndIf
            Case 1
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') = 0 And _
                    StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') = 0 Then
                    If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                        $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                    Else
                        $sHold &= $aFSplit[$iCC] & Chr(1)
                    EndIf
                EndIf
            Case 2
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Or _
                    StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then
                    If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                        $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                    Else
                        $sHold &= $aFSplit[$iCC] & Chr(1)
                    EndIf
                EndIf
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc;==> _FileListToArrayEx
can i search and delete AutoIt exe's instead of mp3?

can you add a simple progress bar while deleting?

Share this post


Link to post
Share on other sites
TehWhale

L0veUk, I'm sure you can edit not even one line, to fit your needs.

Share this post


Link to post
Share on other sites
UltraFine

L0veUk, I'm sure you can edit not even one line, to fit your needs.

i will try to do myself, but need your help to know how...

Share this post


Link to post
Share on other sites
TehWhale

Any why would you need to delete all AutoIt .exe's on your computer unless you want to get rid of the evidence of a virus?

Share this post


Link to post
Share on other sites
UltraFine

Any why would you need to delete all AutoIt .exe's on your computer unless you want to get rid of the evidence of a virus?

i have one more pc, before giving it to anyone i want to delete all my compiled autoit exe's and au3 files in it but it will take too much time by hand to detect and delete only autoit exe's.

Share this post


Link to post
Share on other sites
FreeFry

If you're "giving" the pc to someone else, just do a simple format of the partitions on the drive. No need to delete anything.

Share this post


Link to post
Share on other sites
rudi

Hi.

i have one more pc, before giving it to anyone i want to delete all my compiled autoit exe's and au3 files in it but it will take too much time by hand to detect and delete only autoit exe's.

I again suspect that you to intend to code some foolish malware. Well, fortunatley yxou seem to bie unable to modify the small CMD line I've already given to you :mellow:

In case you want to wipe any valuable content of your OWN hard disk, search google for "wipe harddisk", there are plenty of tools out there to do so.

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
slayer9

Hi everyone. Sorry if i'm wrong reviveing such a dead topic. i'm interested in Pain's first post language. is that visual basic or what? Thanx in advance

Share this post


Link to post
Share on other sites
Nessie

Its better to start a new topic instead of reviveing a very old topic. By the way look at and you will find the answer to your question.

Hi!


My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites
slayer9

Hi Nessie and thanks for your answer. when i'll have a question i'll start a new topic.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.