pcmagas Posted November 30, 2009 Share Posted November 30, 2009 hello guys. i am new member in your forum. I want your help for making a script that renames all the files in a folder. Example: we have a folder path like C:\test and it has some files in it. The thing i want the script to do is to take the first file in the folder and rename it and then the next file till the last file. Thank you a lot, Pcmagas Link to comment Share on other sites More sharing options...
Developers Jos Posted November 30, 2009 Developers Share Posted November 30, 2009 hello guys. i am new member in your forum.I want your help for making a script that renames all the files in a folder.Example: we have a folder path like C:\test and it has some files in it. The thing i want the script to do is to take the first file in the folder and rename it and then the next file till the last file.Thank you a lot,PcmagasI am sure this has been asked before.... anyway: open the helpfile and look for FileFindFirst(), FileFindNext() and FileMove()Enjoy your research,Jos 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...
Xenobiologist Posted November 30, 2009 Share Posted November 30, 2009 Or have a look at the example of _FileListToArray Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
pcmagas Posted December 1, 2009 Author Share Posted December 1, 2009 thank you a lot for your answers but i am new in scripting and i cannot figure out exactly how to make it work: This is my code: expandcollapse popupdim $animepath = inputbox( " Anime Path", "The path for the anime folder:") $animename = inputbox( " Anime Name", "The name of the anime: ") $animeartist = "ani-planet.net" $animeartist2 = "dl@ani-planet.net" Dim $FileCount = 0 $FileCount2 = 0 Func ScanFolder($SourceFolder) Local $Search Local $File Local $FileAttributes Local $FullFilePath $Search = FileFindFirstFile($SourceFolder & "\*.*") While 1 If $Search = -1 Then ExitLoop EndIf $File = FileFindNextFile($Search) If @error Then ExitLoop $FullFilePath = $SourceFolder & "\" & $File $FileAttributes = FileGetAttrib($FullFilePath) If StringInStr($FileAttributes,"D") Then ScanFolder($FullFilePath) Else LogFile($FullFilePath) EndIf WEnd FileClose($Search) EndFunc Func LogFile($FileName) FileWriteLine(@ScriptDir & "\FileList.txt",$FileName) $FileCount += 1 ToolTip($FileName,0,0) EndFunc ScanFolder($animepath) MsgBox(0,"Done","Folder Scan Complete. Scanned " & $FileCount & " Files") MsgBox(0,"Done",$FileCount & " Files") $FileCount2 = $FileCount Func FileRename($SourcePath) for $FileCount= 1 to $FileCount= $FileCount2 MsgBox(0, "Count down!", $FileCount) Next MsgBox(0,"", "Blast Off!") EndFunc Can you help me fix it a bit especially in the filerename fuction. Sorry for the message boxes in the file rename fuction but i am still testing it . Thank you a lot Link to comment Share on other sites More sharing options...
99ojo Posted December 1, 2009 Share Posted December 1, 2009 (edited) Hi, to start with: expandcollapse popup#include <file.au3> Global $filearray, $dirarray, $sourcepath = "c:\test", $dirfile = @ScriptDir & "\dir.txt" If FileExists ($dirfile) Then FileDelete ($dirfile) _getdir ($sourcepath) _getfile () Func _getdir ($startpath) Local $temparray $temparray = _FileListToArray ($startpath, "*", 2) If @error Then Return Else $file = FileOpen ($dirfile, 1) For $i = 1 To UBound ($temparray) - 1 FileWriteLine ($file, $startpath & "\" & $temparray [$i]) Next FileClose ($file) For $i = 1 To UBound ($temparray) - 1 _getdir ($startpath & "\" & $temparray [$i]) Next EndIf EndFunc Func _getfile () _FileReadToArray ($dirfile, $dirarray) For $i = 1 To UBound ($dirarray) - 1 FileRename ($dirarray [$i]) Next EndFunc ;example for renaming extension from .* to .bak Func FileRename($path) $filearray = _FileListToArray ($path, "*.*", 1) If @error = 4 Then MsgBox (0,"",$path & ": No files found!") Else For $i = 1 To UBound ($filearray) - 1 MsgBox (0,"Move....", "Source: " & $path & "\" & $filearray [$i] & @CRLF & "Dest: " & $path & "\" & _ StringLeft ($filearray [$i], StringInStr ($filearray [$i], ".") - 1) & ".bak") ;FileMove ($sourcepath & "\" & $filearray [$i], $sourcepath & "\" & StringLeft ($filearray [$i], StringInStr ($filearray [$i], ".") - 1) & ".bak") Next EndIf EndFunc ;-)) Stefan Edited December 1, 2009 by 99ojo Link to comment Share on other sites More sharing options...
pcmagas Posted December 1, 2009 Author Share Posted December 1, 2009 hello thank you for you reply was very usefull but i can not modify this part of the code Func FileRename($path) $filearray = _FileListToArray ($path, "*.*", 1) If @error = 4 Then MsgBox (0,"",$path & ": No files found!") Else For $i = 1 To UBound ($filearray) - 1 MsgBox (0,"Move....", "Source: " & $path & "\" & $filearray [$i] & @CRLF & "Dest: " & $path & "\" & _ StringLeft ($filearray [$i], StringInStr ($filearray [$i], ".") - 1) & ".bak") ;FileMove ($sourcepath & "\" & $filearray [$i], $sourcepath & "\" & StringLeft ($filearray [$i], StringInStr ($filearray [$i], ".") - 1) & ".bak") Next EndIf EndFunc This fuction make the extension from *.* to .bak but it doest work for all the files just for the first . Can you please explain to me how to make it change the filename from the first till the last file? Thanks a Lot Sorry for my noobness Link to comment Share on other sites More sharing options...
99ojo Posted December 2, 2009 Share Posted December 2, 2009 Hi, it should. So you have to debug the array: 1) Add #include <array.au3> at the beginning of your script 2) After line $filearray = _FileList.... add a _ArrayDisplay ($filearray). This will show your files, that are in the given $path (hopefully). The renaming process is only working with files of following structure: file name what ever you want.xxx You must have no dot in between filename and a .xxx as extension. ;-)) Stefan Link to comment Share on other sites More sharing options...
pcmagas Posted December 2, 2009 Author Share Posted December 2, 2009 thank you a lot 99ojo i have made it work 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