Sign in to follow this  
Followers 0
KSum

Filemove with Wildcards in the file's middle

6 posts in this topic

#1 ·  Posted (edited)

Hello,

I am trying to use a wildcard in the move command:

FileMove ("test*.txt" , "testNewName*.txt", 8)

or

FileMove ("*test*.txt" , "*testNewName*.txt", 8)

Basically, the user will supply the file names, with wildcards, and I wanted to rename the files. But it doesn't see to work well. In the first example, I might have files named the same with different extensions (.pdf and .doc for example) The wildcard portion would typically be numbers, but not always the same amount. Am I trying to abuse Filemove? Am I going to have to pull all the files into an array, and then use code to create the new name? Is there an easier way?

AutoIt v3.2.8.1

Regards,

Karl

Edited by KSum

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I would suggest using _FileListToArray(). You can create an array of filenames from a directory and then create a loop that will react based on the filenames.

i.e.

#include <File.au3>
$filelist = _FileListToArray("C:\")
For $i = 1 To $filelist[0]
    If StringRegExp($filelist[$i], "(test)*(.txt)") Then
        FileMove($filelist[$i],"C:\testNewName" & StringRegExpReplace($filelist[$i],"(test)",""),8)
    EndIf
Next
Edited by Airwolf

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

Or just _FileListToArray("C:\", "test*.txt")

Share this post


Link to post
Share on other sites

Or just _FileListToArray("C:\", "test*.txt")

I've never used the filter option in _FileListToArray(); I guess I was a bit blind all of those times I looked at it in the help file... LOL

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

I guess I will write something up with the _FileListToArray(). I was just trying to be lazy about the coding, as I want to be able to have more than 1 wildcard:

Change 1test123.txt

To 1NewTest123.bat

Change 33test789.txt

To 33NewTest789.bat

So the search would be for *test*.txt and the replacement would be *NewTest*.bat I am even willing to use a DOS command, but REN (Rename) doesn't work here, and neither does a couple other things I tried.

Oh well, guess I'll have to put something together with a GUI and all the bells and whistles now...

Thank you all for your help!

Karl

Share this post


Link to post
Share on other sites

Sorry, I missed the use of StringRegExpReplace() THAT should do what I need for the complex search/replacements. I just need to parse the input out into the proper form. (OK, I need to figure out hte proper form as I am use to a different Regular Expression syntax, but no big deal there.)

I think I am on my way here! Again, thank you!

Karl

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