Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

renaming all files in folder


  • Please log in to reply
7 replies to this topic

#1 LoneReaper

LoneReaper

    Seeker

  • Active Members
  • 21 posts

Posted 14 September 2004 - 08:15 PM

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







#2 Jos

Jos

    Je maintiendrai

  • Developers
  • 23,351 posts

Posted 14 September 2004 - 08:25 PM

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... http://www.autoitscript.com/forum/index.ph...indpost&p=30391
just change it to rename in stead of delete files...

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#3 LoneReaper

LoneReaper

    Seeker

  • Active Members
  • 21 posts

Posted 14 September 2004 - 08:36 PM

$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?

#4 Jos

Jos

    Je maintiendrai

  • Developers
  • 23,351 posts

Posted 14 September 2004 - 08:51 PM

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...


Plain Text         
; ; 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 by JdeB, 14 September 2004 - 08:51 PM.

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#5 LoneReaper

LoneReaper

    Seeker

  • Active Members
  • 21 posts

Posted 14 September 2004 - 09:07 PM

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.

#6 Jos

Jos

    Je maintiendrai

  • Developers
  • 23,351 posts

Posted 14 September 2004 - 09:17 PM

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:
Plain Text         
; ; 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

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#7 LoneReaper

LoneReaper

    Seeker

  • Active Members
  • 21 posts

Posted 14 September 2004 - 09:18 PM

Thank you SO MUCH!

WORKS PERFECT!!! :ph34r:

#8 the_lord_mephy

the_lord_mephy

    I can't believe I asked this many questions =-o

  • Active Members
  • PipPipPipPipPipPip
  • 495 posts

Posted 14 September 2004 - 11:58 PM

Damn JdeB your an insane scripter :ph34r:
My site for HTML Help :)

Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?

View Post





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users