# Change File Name

## Recommended Posts

Hey all

So I was trying to change a file name using FileMove, but it didn't work for me.

(Maybe I just didn't use it in the right way?)

Is there another way to change a file name?

Thank you!

##### Share on other sites

How do you call FileMove and what is the return value?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:

##### Share on other sites

I've simply copied the line from the help file:

http://www.autoitscript.com/autoit3/docs/functions/FileMove.htm

FileMove("C:\foo.au3", "D:\mydir\bak.au3")

and all I did was just change the destination.

Sometimes it worked, sometimes it didn't.. Weird.

EDIT: It does work right now. Even weirder

However now I have another problem.

How do I use a variable in this code?

I need to change the files names and add a number to the beginning.

e.g:

a.txt --> 3a.txt

b.txt --> 3b.txt

I've tried something like this:

$num = 11 FileMove("C:\text.txt", "c:\" &$num & "text.txt")

But it didn't work of course..

Edited by Omga4000

##### Share on other sites

Change your code to do some error checking

$num = 11$iResult = FileMove("C:\text.txt", "c:\" & $num & "text.txt") MsgBox(0,"", "Result: " &$iResult)
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:

##### Share on other sites

Now I get it.. Thank you!

## Create an account

Register a new account

• ### Similar Content

• By Trisha
Hello,
I Have clicked on save as option to save a file, while doing that I need to rename a file appending with sysdate. I have searched in google find the below one line of code:
FileMove("C:\somefile.txt", "C:\somefile1.txt"), When I am trying to append with sysdate. It is not happening. Please help me out  with the small issue.
• By Ambient
I have tried several way sto get this to work to no avail. Any help would be appreciated. #include <ListViewConstants.au3> #include <GuiListView.au3> #include "GuiListViewEx.au3" $idItem = GUICtrlCreateListViewItem($r & " | " & $c &$adoRs.Fields("TransactionAmount").value & " | " & $Timestamp & " | " & _StringProper($adoRs.Fields("Tillid").value) & @CRLF & @CRLF & "Card Number : " & $cardnum & " " ,$idListView) ConsoleWrite( "IDITEM" & $idItem) If STRINGLEFT($adoRs.Fields("TransactionAmount").value,1)= "-" Then Consolewrite(" String is Negative" & @CRLF) ;Drops in Here as expected ;GUICtrlSetColor(-1, $COLOR_RED) ; Colour line if item is negative this didn' work$TxC= _GUICtrlListView_SetTextColor($hListView,$CLR_RED) ; I also tried $TxC= _GUICtrlListView_SetTextColor(-1, 0xFF0000) CONSOLEWRITE("TEXTCOLOUR RETURNED " &$TxC & @crlf) ; This is returning True ELSE Consolewrite(" String is NOT Negative" & @CRLF) EndIf
• By lewisg
Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script.

$FilePath = "C:\AutoIT\LED"$FilePathPlus = $FilePath & "\plink.exe"$Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " &$FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g. ShellExecuteWait , etc. The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2. Searching here and Google has not yielded any clues that helped. • By rudi Hello. I'm too stupid to see my mistake: To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF. Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting The "TIFF Header Format" is easy: Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49) --> II Offset 02h, 2 Byte = Version Nr. Offset 04h, 4 Byte = pointer to first IFD entry Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3 Howto read and analyse the binary content correctly? This is my messy, not operational code:$sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' &$content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h)$type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :$type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console$ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :$ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF)$content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :$content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for$i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :$next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console$Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :$Chr = ' & \$Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi.
111111.TIF
• By nacerbaaziz
Hi dear
I want create retractable bar using autoit
I tried creating slider, but there's a problem with screen reader for the blind, so is there another retractable tape?
It is advisable to not accept dragging with the keybord only with  mouse
note:
This bar is needed in the process of raising and lowering the volume
I hope that there is a solution to do that
×

• Wiki

• Back

• Git