Sign in to follow this  
Followers 0
cavalli

Isolate text file name from .txt (extension)

5 posts in this topic

#1 ·  Posted (edited)

Hello,
I have basic knowledge of AutoIt3 and I looked at this forum very often for my codes, but is a first time that i make a new topic, so i'm new on this forum, and before ask for help I want just thank people who spend their time to answer questions and help newbies like me  :)
 
I do not know if the topic title is clear to you, let me explain my problem : 
 
I have a combobox that points to a folder, in the folder I have text files, when I choose one of these text files, I want the name of the file is assigned to a variable, but without the extension, for example the "mytxtfile.txt" file, I just want to retrieve in my variable "mytxtfile" 
 
Hopefully I was clear in my topic :)
Edited by cavalli

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the forum!

Please have a look at function _PathSplit.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here some variants for filename only:

$sText = "mytxtfile.txt"
$way1 = StringLeft($sText, StringInStr($sText, ".", 0, -1) - 1)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $way1 = ' & $way1 & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
$way2 = StringTrimRight($sText, StringLen($sText) - StringInStr($sText, ".", 0, -1) + 1)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $way2 = ' & $way2 & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
$way3 = StringRegExpReplace($sText, "(.*)\..*", "$1")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $way3 = ' & $way3 & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
$way4 = StringRegExp($sText, "(.*)\..*", 3)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $way4 = ' & $way4[0] & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

It's not clear whether you have a full path string or only the filename!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Hello guys, thank you for your response.

Thanks UEZ you gave me the solution :) it works!!

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