Sign in to follow this  
Followers 0
Info

Recursive file name changer

1 post in this topic

#1 ·  Posted (edited)

This uses Melba23's UDF.

#include <GuiConstantsEx.au3>
#include <Recfilelisttoarray.au3>

$win = GUICreate("Name Changer",250,106)
$b1 = GUICtrlCreateButton("...",208,2,40,25)
$b2 = GUICtrlCreateButton("Start",188,34,60,25)
$inp1 = GUICtrlCreateInput("",4,4,200,21)
$inp2 = GUICtrlCreateInput("BA",50,34,34,21)
$inp3 = GUICtrlCreateInput("SO",112,34,34,21)
$prog = GUICtrlCreateProgress(4,66,242,18)
$lab = GUICtrlCreateLabel("",6,88,1000,25)
GUICtrlCreateLabel("Change",6,38,37)
GUICtrlCreateLabel("to",94,38,10)
GUICtrlSetLimit($inp2,10)
GUICtrlSetLimit($inp3,10)
GUISetState()

While 1
    Switch GUIGetMsg()
    Case -3
        _Close()
        
    Case $b1
        $f = FileSelectFolder("Select a folder","")
        If Not @error Then
            GUICtrlSetData($inp1,$f)
        EndIf
    
    Case $b2
        $read = GUICtrlRead($inp1)
        $sFrom = GUICtrlRead($inp2)
        $sTo = GUICtrlRead($inp3)
        
        If $read <> "" And $sFrom <> "" And $sTo <> "" Then
            GUICtrlSetState($b1,$GUI_DISABLE)
            GUICtrlSetState($b2,$GUI_DISABLE)
            GUICtrlSetState($inp1,$GUI_DISABLE)
            GUICtrlSetState($inp2,$GUI_DISABLE)
            GUICtrlSetState($inp3,$GUI_DISABLE)
            If StringRight($read,1) <> "\" Then
                $read &= "\"
                GUICtrlSetData($inp1,$read)
            EndIf
            
            $a = _RecFileListToArray($read,"*",1,1)
            
            If @error Then
                
                GUICtrlSetData($lab,"Bad path.")
                
            ElseIf IsArray($a) Then
                
                $iProg = 0
                GUICtrlSetData($prog,$iProg)
                
                $fromLen = StringLen(GUICtrlRead($inp2))
                
                For $i = 1 To $a[0]
                    GUICtrlSetData($lab,$a[$i])
                    If StringLeft(_PathGetFile($a[$i]), $fromLen) = $sFrom Then
                        $s = $read & _PathGetDirectory($a[$i]) & $sTo & StringTrimLeft(_PathGetFile($a[$i]),$fromLen)
                        FileMove($read & $a[$i], $s, 1)
                    EndIf
                    $iProg += 100/$a[0]
                    GUICtrlSetData($prog,$iProg)
                Next
                
            EndIf
            
            GUICtrlSetData($lab,"Done.")
            GUICtrlSetData($prog,0)
            If @OSVersion = "WIN_7" Then SoundSetWaveVolume(100)
            SoundPlay(@WindowsDir & "\media\Windows Ding.wav")
            
            GUICtrlSetState($b1,$GUI_ENABLE)
            GUICtrlSetState($b2,$GUI_ENABLE)
            GUICtrlSetState($inp1,$GUI_ENABLE)
            GUICtrlSetState($inp2,$GUI_ENABLE)
            GUICtrlSetState($inp3,$GUI_ENABLE)
        EndIf
    EndSwitch
WEnd

Func _Close()
    GUIDelete($win)
    Exit
EndFunc

Func _PathGetFile($dir)
    $str = StringInStr($dir,"\",0,-1)
    If $str > 0 Then
        Return StringTrimLeft($dir,$str)
    EndIf
    
    Return $dir
EndFunc

Func _PathGetDirectory($dir)
    $str = StringInStr($dir,"\",0,-1)
    If $str > 0 Then
        Return StringLeft($dir,$str)
    Else
        Return ""
    EndIf
EndFunc

With this you can change file names that start with a particular string to a different name.

For example: BAasdasd.h will be changed to SOasdasd.h.

Edited by Info

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  
Followers 0