Jump to content

Rename a selected file


Recommended Posts

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

@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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...