Jump to content



Photo

_filerename Udf


  • Please log in to reply
10 replies to this topic

#1 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 19 April 2006 - 07:24 PM

I made file renaming easier
AutoIt         
;=============================================================================== ; ; 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 by RazerM, 19 May 2006 - 03:30 PM.

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.





#2 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 20 April 2006 - 03:00 PM

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.

#3 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 20 April 2006 - 03:29 PM

i thought some people would like this

Doesn'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 by SmOke_N, 20 April 2006 - 03:32 PM.

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.


#4 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 20 April 2006 - 03:33 PM

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.

#5 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 20 April 2006 - 03:42 PM

I just thought this was easier

There'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 by SmOke_N, 20 April 2006 - 03:50 PM.

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.


#6 MHz

MHz

    Just simple

  • MVPs
  • 5,400 posts

Posted 20 April 2006 - 03:45 PM

Perhaps an extra requirement?

; Requirement(s): #Include file.au3 and AutoIt Beta > v3.1.1.76

I would rather see 0 being returned on failure. It would make the UDF usable as a boolean.

#7 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 20 April 2006 - 03:52 PM

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

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.


#8 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 20 April 2006 - 04:58 PM

ok it returns 0 on failure, which makes more sense i suppose
Plain Text         
;=============================================================================== ; ; 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.

#9 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 20 April 2006 - 05:15 PM

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 EndFunc
Looks 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 EndFunc
Already put it to use in one of my scripts :think:.

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.


#10 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 20 April 2006 - 05:41 PM

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.

#11 MHz

MHz

    Just simple

  • MVPs
  • 5,400 posts

Posted 20 April 2006 - 06:21 PM

Nice update. :think:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users