Jump to content
Sign in to follow this  
Kenton

Rename a selected file

Recommended Posts

Kenton

Hi,

I want to write a small bot that renames a selected file starting with year, month, date as follows:

FileMove ("C:\test\Somefile.txt", "C:\test\" & @YEAR & @MON & @MDAY & " - " & "Somefile.txt")

This works perfectly but I need the current path + filename as a string. The user will be on a filename in the windows explorer when they activate this bot. I am currently activating the bot through a windows shortcut key after I compiled the scrip.

 

Share this post


Link to post
Share on other sites
Kenton

* I need the current path + filename as a string variable

Share this post


Link to post
Share on other sites
Kenton

So I got it to partly work via send key:

Quote

Send("{F2}")
Send("^C")
Send(@YEAR & @MON & @MDAY & " - ")
Send("^V")
Send ("{ENTER}")

But I still have some major issues:

1. I still need a way to add a Shortcut key that will trigger the code from within the windows explorer. Currently, it's only working on itself.

2. I don't like so many Send keys

3. I'll prefer to use variables not the clipboard

 

In my view, the above FileMove is still a better than this Send key 

Any advice will be highly appreciated.....

Share this post


Link to post
Share on other sites
JLogan3o13
Posted (edited)

@Kenton welcome to the forum. Look at _FileListToArray in the help file. You basically read in all files in that directory to an Array, then loop through the array with your FileMove command.

Here is a generic example. Imagine a Test folder on the desktop titled test, with a number of text files that I want to rename in numbered sequence:

#include <File.au3>

Local $sPath = @DesktopDir & "\Test"
Local $aFiles = _FileListToArray($sPath, "*.txt", $FLTA_FILES, True)

    For $a = 1 To $aFiles[0]
        FileMove($aFiles[$a], $sPath & "\" & $a & ".txt")
    Next

You should be able to modify this to suit your needs; if you run into trouble, please post your code and we will do our best to assist :)

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

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  

×