LoneReaper Posted September 14, 2004 Share Posted September 14, 2004 i have a lot of files in a folder and sub folders that do not have extensions. How would i go to folder C:\Internet\data\www.blah.com\blah and rename all files in this folder and all files in the sub folder to have .htm Link to comment Share on other sites More sharing options...
Developers Jos Posted September 14, 2004 Developers Share Posted September 14, 2004 i have a lot of files in a folder and sub folders that do not have extensions. How would i go to folder C:\Internet\data\www.blah.com\blah and rename all files in this folder and all files in the sub folder to have .htm <{POST_SNAPBACK}>posted this yesterday... #30391 just change it to rename in stead of delete files... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
LoneReaper Posted September 14, 2004 Author Share Posted September 14, 2004 $L_Msg = "" ; init variables $Version = "0.2" $dir="C:\data\user" $Dircount = 0 $n_FileCount = 0 $n_FileSize = 0 $begin = TimerStart() ; _Remove_Files(root dir, inclu subdirs,remove files older than) $rc = _Remove_Files($Dir, 1,14) Exit this is the code that i need right? What would i change? Link to comment Share on other sites More sharing options...
Developers Jos Posted September 14, 2004 Developers Share Posted September 14, 2004 (edited) Here's a changed script that should be close but i didn't test it... Change the $dir="C:\data\user" to the root of the tree you want to scan. It will rename all files that don't have a DOT in it and add ".htm" to it. Make sure you test it first on some test files... expandcollapse popup; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win9x/NT ; Author: Jos van der Zande ; ; Script Function: ; Rename files *. to *.htm AutoItSetOption ( "RunErrorsFatal", 0) ;AutoItSetOption ( "TrayIconHide", 1) Break(0) $Hotkey = "{Pause}" HotKeySet ($Hotkey ,"StopExec") $L_Msg = "" ; init variables $Version = "0.1" $dir="C:\data\user" $Dircount = 0 $n_FileCount = 0 $n_FileSize = 0 $begin = TimerStart() ; _Rename_Files(root dir, inclu subdirs) $rc = _Rename_Files($Dir, 1) Exit ;=============================================================================== ; ;=============================================================================== Func _Rename_Files($T_Dir,$T_Incl_SubDir) Dim $n_Dirnames[200000][2]; max number of directories that can be counted Local $n_DirCount = 0 Local $n_File Local $n_Search Local $n_tFile Local $n_Fdate $T_DirCount = 1 $T_FileCount = 0 $T_FileSize = 0 ; remove the end \ If StringRight($T_Dir,1) = "\" then $T_Dir = StringTrimRight($T_Dir,1) $n_Dirnames[$T_DirCount][0] = $T_Dir $n_Dirnames[$T_DirCount][1] = 0 $T_Incl_SubDir = Int($T_Incl_SubDir) ; Exit if base dir doesn't exists If Not FileExists($T_Dir) then Return 0 ; keep on looping until all directories are counted While $T_DirCount > $n_DirCount $n_DirCount = $n_DirCount + 1 $n_Search = FileFindFirstFile($n_Dirnames[$n_DirCount][0] & "\*.*" ) If $n_Search = -1 Then ContinueLoop EndIf ShowMenu("Processing directory:" & @LF & $n_Dirnames[$n_DirCount][0],0) While 1 $n_File = FileFindNextFile($n_Search) If @error Then ExitLoop $n_tFile = $n_Dirnames[$n_DirCount][0] & "\" & $n_File ShowMenu(" File :" & $n_File,2) ; skip these references if $n_File = "." or $n_File = ".." then ContinueLoop EndIf ; if Directory than add to the list to be processed later If StringInstr(FileGetAttrib ( $n_tFile ),"D") > 0 then If $T_Incl_SubDir = 1 then $T_DirCount = $T_DirCount + 1 $n_Dirnames[$T_DirCount][0] = $n_tFile $n_Dirnames[$T_DirCount][1] = 0 EndIf Else ; Rename file when it doesn't contain a dot If StringInStr($n_tFile,".") = 0 then FileMove($n_tFile,$n_tFile & ".htm") EndIf EndIf Wend FileClose($n_Search) Wend Return ( 1 ) EndFunc ; ;====================================== ; Stop executing when Hotkey is pressed ;====================================== Func StopExec() $mrc=Msgbox(4,"Cancel Execution?","Your pressed " & $Hotkey & ". Do you want to cancel the Program?") if $mrc = 6 then Exit EndIf Return EndFunc ;===================================================== ; Show Splash screen or update its content ;===================================================== Func ShowMenu($g_msg,$concat) $W_Title=" file remove Utility (ver:" & $Version & ") Press " & $Hotkey & " to stop execution" $D_msg = "" If $concat > 0 Then If $concat = 1 Then $L_msg = $L_msg & @LF & $g_msg $d_msg = $L_msg Else $d_msg = $L_msg & @LF & $g_msg EndIf Else $L_msg = $g_msg $d_msg = $g_msg EndIf if WinExists($W_Title) then ControlSetText($W_Title,"","Static1",$d_msg) else SplashTextOn($W_Title,$d_msg,800,100,1,1,6,"Courier",10,600) endif Return 0 EndFunc Edited September 14, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
LoneReaper Posted September 14, 2004 Author Share Posted September 14, 2004 I changed $dir="C:\internet\data\" and it didnt do anything, it brought a message box to the top for a split second but it didnt rename anything. Link to comment Share on other sites More sharing options...
Developers Jos Posted September 14, 2004 Developers Share Posted September 14, 2004 I changed $dir="C:\internet\data\" and it didnt do anything, it brought a message box to the top for a split second but it didnt rename anything. <{POST_SNAPBACK}>Did some testing and made a correction in it... see if this works for you: expandcollapse popup; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win9x/NT ; Author: Jos van der Zande ; ; Script Function: ; Rename files *. to *.htm AutoItSetOption ( "RunErrorsFatal", 0) ;AutoItSetOption ( "TrayIconHide", 1) Break(0) $Hotkey = "{Pause}" HotKeySet ($Hotkey ,"StopExec") $L_Msg = "" ; init variables $Version = "0.1" $dir="C:\internet\data\" $Dircount = 0 $n_FileCount = 0 $n_FileSize = 0 $begin = TimerStart() ; _Rename_Files(root dir, inclu subdirs) $rc = _Rename_Files($Dir, 1) Exit ;=============================================================================== ; ;=============================================================================== Func _Rename_Files($T_Dir,$T_Incl_SubDir) Dim $n_Dirnames[200000][2]; max number of directories that can be counted Local $n_DirCount = 0 Local $n_File Local $n_Search Local $n_tFile Local $n_Fdate $T_DirCount = 1 $T_FileCount = 0 $T_FileSize = 0 ; remove the end \ If StringRight($T_Dir,1) = "\" then $T_Dir = StringTrimRight($T_Dir,1) $n_Dirnames[$T_DirCount][0] = $T_Dir $n_Dirnames[$T_DirCount][1] = 0 $T_Incl_SubDir = Int($T_Incl_SubDir) ; Exit if base dir doesn't exists If Not FileExists($T_Dir) then Return 0 ; keep on looping until all directories are counted While $T_DirCount > $n_DirCount $n_DirCount = $n_DirCount + 1 $n_Search = FileFindFirstFile($n_Dirnames[$n_DirCount][0] & "\*" ) If $n_Search = -1 Then ContinueLoop EndIf ShowMenu("Processing directory:" & @LF & $n_Dirnames[$n_DirCount][0],0) While 1 $n_File = FileFindNextFile($n_Search) If @error Then ExitLoop $n_tFile = $n_Dirnames[$n_DirCount][0] & "\" & $n_File ShowMenu(" File :" & $n_File,2) ; skip these references if $n_File = "." or $n_File = ".." then ContinueLoop EndIf ; if Directory than add to the list to be processed later If StringInstr(FileGetAttrib ( $n_tFile ),"D") > 0 then If $T_Incl_SubDir = 1 then $T_DirCount = $T_DirCount + 1 $n_Dirnames[$T_DirCount][0] = $n_tFile $n_Dirnames[$T_DirCount][1] = 0 EndIf Else ; Rename file when it doesn't contain a dot If StringInStr($n_File,".") = 0 then FileMove($n_tFile,$n_tFile & ".htm") EndIf EndIf Wend FileClose($n_Search) Wend Return ( 1 ) EndFunc ; ;====================================== ; Stop executing when Hotkey is pressed ;====================================== Func StopExec() $mrc=Msgbox(4,"Cancel Execution?","Your pressed " & $Hotkey & ". Do you want to cancel the Program?") if $mrc = 6 then Exit EndIf Return EndFunc ;===================================================== ; Show Splash screen or update its content ;===================================================== Func ShowMenu($g_msg,$concat) $W_Title=" file remove Utility (ver:" & $Version & ") Press " & $Hotkey & " to stop execution" $D_msg = "" If $concat > 0 Then If $concat = 1 Then $L_msg = $L_msg & @LF & $g_msg $d_msg = $L_msg Else $d_msg = $L_msg & @LF & $g_msg EndIf Else $L_msg = $g_msg $d_msg = $g_msg EndIf if WinExists($W_Title) then ControlSetText($W_Title,"","Static1",$d_msg) else SplashTextOn($W_Title,$d_msg,800,100,1,1,6,"Courier",10,600) endif Return 0 EndFunc SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
LoneReaper Posted September 14, 2004 Author Share Posted September 14, 2004 Thank you SO MUCH! WORKS PERFECT!!! Link to comment Share on other sites More sharing options...
the_lord_mephy Posted September 14, 2004 Share Posted September 14, 2004 Damn JdeB your an insane scripter My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now