Sign in to follow this  
Followers 0
WLGades

Renaming Files in a Directory

5 posts in this topic

I'm trying to rename all the files in a directory given the directory name. So if the directory name is "1023", and the files are called "a.csv", "b.csv", and "c.csv", I want "a 1023.csv", "b 1023.csv", and "c 1023.csv" after I've run the script.

So, I've figured out how to get all the files in a directory from the help file, and I know I can use FileMove to rename the file, but how do I actually get the directory name from the path description? I looked through the library with little success.

Share this post


Link to post
Share on other sites



$array = StringSplit('c:\1023\a.csv', '\')
$result = $array[0] - 1
MsgBox(4096,'debug:' , '$answer:' & $array[$result])
Here is an example. StringSplit splits the address by the back slashes, and turns it into an array. We just extract the 2nd last entry in the array to find out the directory name.

Share this post


Link to post
Share on other sites

You may have to split the filename into it's parts.

http://www.autoitscript.com/fileman/users/Valik/path.au3 may help.

Or search the forum for "splitpath"

Share this post


Link to post
Share on other sites

The problem is that requires your knowing the entire path name before running it. Is there any way to get the path name of the files that are being returned? Or even the path of the currently executing AutoIt script?

You may have to split the filename into it's parts.

http://www.autoitscript.com/fileman/users/Valik/path.au3 may help.

Or search the forum for "splitpath"

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@ScriptDir

@WorkingDir

You can set the working dir to something relative to it's current value and it will be updated with the absolute path.

FileChangeDir ( "..\" )

msgbox(0, "Test", @WorkingDir)

Edited by kanumi

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  
Followers 0