Jump to content

Recommended Posts

Posted (edited)

if your like me have loads of mp3's and cant be bothered to rename them manually.. then try this

******i have tested this EXTENSIVLEY but cannot be held responsible if i messes up your files*******

^^^^^^^^^^^^ had to say just incase someone says its gone horribly wrong.. ;) so ensure the test tick is enabled first.

post-12971-1220090851_thumb.jpg

#include<Array.au3>
#include<File.au3>
#include<ButtonConstants.au3>
#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
#include<String.au3>

Opt("GUIOnEventMode", 1)
Global $file, $newname, $srce, $srDir, $srDrive, $srExt, $srFName, $suc, $typ, $sc, $List1, $files

$Form1 = GUICreate("Form1", 378, 447, 582, 251)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")
$input = GUICtrlCreateInput("Input Folder", 16, 8, 313, 21)

$output = GUICtrlCreateInput("Target Folder", 16, 40, 313, 21)

$input_button = GUICtrlCreateButton("", 336, 8, 25, 25, $BS_ICON)
GUICtrlSetOnEvent(-1, "input")
GUICtrlSetImage(-1, "shell32.dll", 46, 0)

$output_button = GUICtrlCreateButton("", 336, 40, 25, 25, $BS_ICON)
GUICtrlSetOnEvent(-1, "output")
GUICtrlSetImage(-1, "shell32.dll", 46, 0)

$Checkbox1 = GUICtrlCreateCheckbox("Test (Output to Listview only)", 16, 72, 181, 17)
GUICtrlSetOnEvent(-1, "checkbox")
GUICtrlSetState(-1, $GUI_CHECKED)

$List1 = GUICtrlCreateList("", 16, 104, 345, 318, BitOR($WS_BORDER, $WS_VSCROLL))

$Button3 = GUICtrlCreateButton("GO!!!", 288, 72, 73, 25, 0)
GUICtrlSetOnEvent(-1, "go")
;GUICtrlSetState(-1,$GUI_DISABLE)
GUISetState(@SW_SHOW)

$log = GUICtrlCreateLabel("Log", 5, 430, 300, 25)


While 1
    Sleep(100)
WEnd


Func go()
    GUICtrlSetData($List1, '')
    GUICtrlSetData($Button3, "Running!!")
    $files = _FileListToArray($sc)
;_ArrayDisplay($files)
    $failed = 0
    For $c = 1 To $files[0]
        GUICtrlSetData($log, "Processed " & $c & " / " & $files[0])
        $srce = $files[$c]
        If $srce <> "" And StringInStr($srce, ".mp3") <> 0 Then
GUICtrlSetData($List1, "Old     :" & $srce & "|")
$newname = StringReplace($srce, '.mp3', '')
$newname=StringRegExpReplace($newname,"\d"," ",0)
ConsoleWrite($newname&@lf)
if StringInStr($newname,"-",0,2)<>0 Then
$newname=StringRegExpReplace($newname,"[\A-]"," ",1)
ConsoleWrite($newname&@lf)
EndIf
if StringInStr($newname,"-")<4 then 
$newname=StringReplace($newname,"-","")
ConsoleWrite($newname&@lf)
EndIf
$newname=StringRegExpReplace($newname,"[^\w-]", " ",0)
ConsoleWrite($newname&@lf)
$newname=StringRegExpReplace($newname,"_"," ")
ConsoleWrite($newname&@lf)
$newname=StringReplace($newname,"-"," - ",1,0)
ConsoleWrite($newname&@lf)
$newname=_StringProper($newname)
ConsoleWrite($newname&@lf)
$ss=StringSplit($newname," ")
$nn=''
for $x=1 to $ss[0]
    if $ss[$x] <> "" Then
   $nn&= $ss[$x]&" "
EndIf
Next
$str=StringTrimRight($nn,1)
ConsoleWrite(">>>"&$str&"<<<"&@lf)
$s=$str&".mp3"



            
            $newname = $s
            GUICtrlSetData($List1, "New   :" & $newname & "|")
            GUICtrlSetData($List1, " |")
            
            
            If GUICtrlRead($Checkbox1) <> 1 Then
                If GUICtrlRead($input) <> GUICtrlRead($output) Then
                    $suc = FileCopy($sc & "\" & $srce, $file & "\" & $newname)
                    $error=0
                    If $suc <> 1 Then
                        do
                        $error+=1
                        $newname = StringReplace($newname,".mp3",$error&".mp3")
                        $suc = Filecopy($sc & "\" & $srce, $file & "\" & $newname)
                        
                            $failed += 1
                        until $suc<>1
                    EndIf
                Else
                    $suc = FileMove($sc & "\" & $srce, $file & "\" & $newname)
                    $error=0
                    If $suc <> 1 Then
                        do
                        $error+=1
                        $newname = StringReplace($newname,".mp3",$error&".mp3")
                        $suc = FileMove($sc & "\" & $srce, $file & "\" & $newname)
                        
                            $failed += 1
                        until $suc<>1
                    EndIf
                EndIf
                
            EndIf
            
            
        EndIf
        Sleep(250)
        
    Next
    MsgBox(262160, "Operation Result", $failed & " Already Exists")
    GUICtrlSetData($Button3, "GO!!!")
EndFunc;==>go

Func quit()
    Exit
EndFunc;==>quit

Func input()

    $sc = FileSelectFolder("Chose Folder to Open","")
    GUICtrlSetData($input, $sc)
EndFunc;==>input

Func output()
    $file = FileSelectFolder("Choose a folder.", '', 1 + 4)
    GUICtrlSetData($output, $file)
EndFunc;==>output

Func checkbox()
EndFunc;==>checkbox
Edited by Aceguy
Posted

This could be pretty handy..

good job!

although its stupid that I can only select a folder in 'My Documents' for the input folder..

Posted (edited)

yep, sorry, did that for test purposes, **changed in first post

$sc = FileSelectFolder("Chose Folder to Open","")

ALSO if the target exists, (test.mp3) it will rename them.

test1.mp3

test2.mp3

test3.mp3

loops until the file can be saved

Edited by Aceguy
  • 2 months later...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...