Sign in to follow this  
Followers 0
Anthony

renameing files

3 posts in this topic

I wish to open a directory and rename the files in the directory.

Ex:

file1.jpg = a.jpg

file2.jpg = b.jpg

file3.jpg = c.jpg

...........

any ideas on how this can be accomplished.

Share this post


Link to post
Share on other sites



I wish to open a directory and rename the files in the directory.

Ex:

file1.jpg = a.jpg

file2.jpg = b.jpg

file3.jpg = c.jpg

...........

any ideas on how this can be accomplished.

if you know the file names it's as simple as using the FileMove function


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I have it copy the files into the same directory so that in case it doesn't work you still have the originals. But i worked up this:

#include <File.au3>
$folder = FileSelectFolder ( "Select folder that contain files to be renamed","")
If $folder = "" Then Exit
msgbox(0,"folder",$folder)
$search = FileFindFirstFile($folder & "\*.*") 
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories were found")
    Exit
EndIf
Local $szDrive,$szDir,$szFName,$szExt
While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop 
    If NOT StringinStr(FileGetAttrib($folder & "\" & $file),"D") Then
        $path = _PathSplit($folder & "\" & $file,$szDrive,$szDir,$szFName,$szExt)
        $number = StringTrimLeft($path[3],4)
        FileCopy($folder & "\" & $file,$folder & "\" & Chr ( 96 + $number ) & $path[4])
    Endif
WEnd

Please keep in mind that it won't work for anything higher than File26.jpg. The reason for this being there are only 26 letters in the alphabet. If you want it to do something like aa for file number 27, then you can use the Mod function.

I am not responsible for anything that happens to your files. I recommend you backup the files before running my script.

The Kandie Man


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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