RazerM Posted April 19, 2006 Posted April 19, 2006 (edited) I made file renaming easier ;=============================================================================== ; ; Function Name: _FileRename ; Description:: Renames a file ; Parameter(s): $s_file - File to be renamed ; $s_name - New filename (e.g. 'newfilename' NO extensions) ; Requirement(s): #Include <file.au3> and AutoIt Beta > v3.1.1.76 ; Return Value(s): 0 - File Error ; 1 - Success ; Author(s): RazerM ; ;=============================================================================== ; Func _FileRename($s_file, $s_name) If Not FileExists($s_file) Then Return 0 Local $szDrive, $szDir, $szFName, $szExt $a_SplitFile = _PathSplit($s_file, $szDrive, $szDir, $szFName, $szExt) $s_renamed = $a_SplitFile[1] & $a_SplitFile[2] & $s_name & $a_SplitFile[4] If Not FileMove($a_SplitFile[0], $s_renamed) Then Return 0 If Not FileExists($s_renamed) Then Return 0 If FileExists($s_file) Then FileDelete($s_file) Return 1 EndFunc Edited May 19, 2006 by RazerM My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
RazerM Posted April 20, 2006 Author Posted April 20, 2006 i thought some people would like this My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Moderators SmOke_N Posted April 20, 2006 Moderators Posted April 20, 2006 (edited) i thought some people would like thisDoesn't FileMove() do this already? Edit:FileMove("C:\foo.au3", "C:\bak.au3", 1)Although, it doesn't delete it I'm sure, and you do have to re-write the path I suppose, so this could be useful. Edited April 20, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
RazerM Posted April 20, 2006 Author Posted April 20, 2006 I just thought this was easier My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Moderators SmOke_N Posted April 20, 2006 Moderators Posted April 20, 2006 (edited) I just thought this was easierThere's an error with your code with _PathSplit()... it is supposed to return an array but you didin't define it... I took the liberty of playing with it a bit.#include <file.au3> _FileRename(@DesktopDir & '\Test.txt', 'RenamedThisFile') Func _FileRename($s_file, $s_name) If Not FileExists($s_file) Then Return -1 Local $szDrive, $szDir, $szFName, $szExt $a_SplitFile = _PathSplit($s_file, $szDrive, $szDir, $szFName, $szExt) $s_renamed = $a_SplitFile[1] & $a_SplitFile[2] & $s_name & $a_SplitFile[4] If Not FileMove($a_SplitFile[0], $s_renamed) Then Return -1 If Not FileExists($s_renamed) Then Return -1 If FileExists($s_file) Then FileDelete($s_file) Return 1 EndFunc Edit: Actually, looking at it, you didn't need to make it a variable I guess... I dunno, but hope it helps anyway. Edited April 20, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
MHz Posted April 20, 2006 Posted April 20, 2006 Perhaps an extra requirement?; Requirement(s): #Include file.au3 and AutoIt Beta > v3.1.1.76I would rather see 0 being returned on failure. It would make the UDF usable as a boolean.
Moderators SmOke_N Posted April 20, 2006 Moderators Posted April 20, 2006 Perhaps an extra requirement?I would rather see 0 being returned on failure. It would make the UDF usable as a boolean.This is true, didn't think of that ... But @ RazerM, I'm sure it will come in handy . Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
RazerM Posted April 20, 2006 Author Posted April 20, 2006 ok it returns 0 on failure, which makes more sense i suppose ;=============================================================================== ; ; Function Name: _FileRename ; Description:: Renames a file ; Parameter(s): $s_file - File to be renamed ; $s_name - New filename (e.g. 'newfilename' NO extensions) ; Requirement(s): #Include <file.au3> and AutoIt Beta > v3.1.1.76 ; Return Value(s): 0 - File Error ; 1 - Success ; Author(s): RazerM ; ;=============================================================================== ; Func _FileRename($s_file, $s_name) If Not FileExists($s_file) Then Return 0 Local $szDrive, $szDir, $szFName, $szExt $a_SplitFile = _PathSplit($s_file, $szDrive, $szDir, $szFName, $szExt) $s_renamed = $a_SplitFile[1] & $a_SplitFile[2] & $s_name & $a_SplitFile[4] If Not FileMove($a_SplitFile[0], $s_renamed) Then Return 0 If Not FileExists($s_renamed) Then Return 0 If FileExists($s_file) Then FileDelete($s_file) Return 1 EndFunc My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Moderators SmOke_N Posted April 20, 2006 Moderators Posted April 20, 2006 Good Deal... This Func _FileRename($s_file, $s_name) If Not FileExists($s_file) Then Return 0 Local $szDrive, $szDir, $szFName, $szExt $a_SplitFile = _PathSplit($s_file, $szDrive, $szDir, $szFName, $szExt) $s_renamed = $a_SplitFile[1] & $a_SplitFile[2] & $s_name & $a_SplitFile[4] If Not FileMove($a_SplitFile[0], $s_renamed) Then Return 0 If Not FileExists($s_renamed) Then Return 0 If FileExists($s_file) Then FileDelete($s_file) Return 1 EndFuncLooks more effective than the original...Func _FileRename($s_file, $s_name) If FileExists($s_file) = 0 Then Return -1 Dim $szDrive, $szDir, $szFName, $szExt _PathSplit($s_file, $szDrive, $szDir, $szFName, $szExt) $s_tempfile = @TempDir & "\" & $szFName & $szExt $s_renamed = $szDrive & $szDir & $s_name & $szExt If FileCopy($s_file, $s_tempfile, 9) = 0 Then Return -1 If FileMove($s_tempfile, $szDrive & $szDir & $s_name & $szExt) = 0 Then Return -1 If FileExists($s_renamed) = 1 Then FileDelete($s_file) FileDelete($s_tempfile) ElseIf FileExists($s_renamed) = 0 Then Return -1 EndIf Return 1 EndFuncAlready put it to use in one of my scripts . Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
RazerM Posted April 20, 2006 Author Posted April 20, 2006 its basically just the one you posted changed a bit:D My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
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