Jump to content

Isolate text file name from .txt (extension)


Go to solution Solved by UEZ,

Recommended Posts

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Solution

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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