Sign in to follow this  
Followers 0
omardj38

File name to string

4 posts in this topic

Hi. I searched around the forum but i didn't found a anwers. My problem is this:

I have a folder with 2 files: a PDF and HTML. Both files have different names but i want rename the file HTML with the same name as the file PDF. The file name's could be different from a PC to another PC. It means that i don't know the name of the files, i only know that the files are PDF and HTML.

My idea to write my code is to read the file name of the *.PDF in that folder and send that string to a variable $name and later rename the file *.HTML with the $name.

But i don't know how to do that or i don't know how to read the file name and send it to a variable.

Any suggestions??

Share this post


Link to post
Share on other sites



Welcome to the forums!

To get the file names, take a look at the examples for FileFindFirstFile/FileFindNextFile, and the UDF _FileListToArray.

You have many options to separate the names from the extensions: StringLeft, StringInStr, StringMid, StringSplit, StringTrimRight, etc...

For the actual renames, use FileMove.

If you get stuck, post what you've been able to come up with so far.

Good luck!


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

Hi. I searched around the forum but i didn't found a anwers. My problem is this:

I have a folder with 2 files: a PDF and HTML. Both files have different names but i want rename the file HTML with the same name as the file PDF. The file name's could be different from a PC to another PC. It means that i don't know the name of the files, i only know that the files are PDF and HTML.

My idea to write my code is to read the file name of the *.PDF in that folder and send that string to a variable $name and later rename the file *.HTML with the $name.

But i don't know how to do that or i don't know how to read the file name and send it to a variable.

Any suggestions??

Try this...

#include <File.au3>
$myPath = "C:\temp123"

$PDFist = _FileListToArray($myPath, "*.pdf", 1)
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
Else
    $HTMList = _FileListToArray($myPath, "*.html", 1)
    If @error = 1 Then
        MsgBox(0, "", "No Files\Folders Found.")
        Exit
    Else
        $FinalName = StringLeft($PDFist[1], (StringLen($PDFist[1])-4)) & ".html"
        FileMove($myPath & "\" & $HTMList[1], $myPath & "\" & $FinalName, 9)
    EndIf
EndIf

Share this post


Link to post
Share on other sites

excellent...............you're my hero............

Gracias.....from Dominican Rep.

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