Sign in to follow this  
Followers 0
ZeR0

How get file extension?

12 posts in this topic

Hi, i need help here...

I coding something and i need get the extension of file, i check the help file, but i not have results... who can help me??? :)

Share this post


Link to post
Share on other sites



#include <File.au3>

$PATH = FileOpenDialog("PATH",@ScriptDir,"All (*.*)")
If Not @error Then
    Dim $szDrive, $szDir, $szFName, $szExt
    $PATH = _PathSplit($PATH,$szDrive,$szDir,$szFName,$szExt)
    MsgBox(0,"",$PATH[4])
EndIf


When the words fail... music speaks

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

quicker solution

$extension = StringReplace(StringRight($path,4),".","")

Cheers,FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

quicker solution

$extension = StringReplace(StringRight($path,4),".","")

Cheers,FireFox.

I don't know what to say about this. Exists file extenstions with more then 4 chars.

When the words fail... music speaks

Share this post


Link to post
Share on other sites

That will different result for .exe, .jpeg and .xhtml etc.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@Andreik

If you insist :)

$split = StringSplit($path, "\")
$name = StringSplit($path[$path[0]], ".")
$ext = $name[2]

Cheers, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

You could immediately split the path using "." as delimiter.

$split = StringSplit($path, ".")
$ext = $split[$split[0]]

[center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]

Share this post


Link to post
Share on other sites

$sFile = "c:\Program Files\AutoIt3\AutoIt3.chm"

$sExt = StringRegExpReplace($sFile, "^.*\.", "")

MsgBox(0, "Extension", $sExt)

Share this post


Link to post
Share on other sites

$filed = FileOpenDialog ("", "", "All (*.*)")

MsgBox (0, "", GetFileExt($filed))

Func GetFileExt($file)
    Return StringRight($file, StringLen($file) - StringInStr($file, ".", 0, -1))
EndFunc  ;==>GetFileExt

Share this post


Link to post
Share on other sites

:) Anyone esle for the competition ? :o

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

:) Anyone esle for the competition ? :o

Cheers, FireFox.

$CurrentFile = "C:\Directory\Directory2\FileNameHere.AnyExtensionLength"

For $YLoop = StringLen ($CurrentFile) to 1 Step -1
    If StringMid ($CurrentFile, $YLoop, 1) == "." Then
         $fl_Ext = StringMid ($CurrentFile, $YLoop)
         $YLoop = 1
    EndIf
Next

Result: $fl_Ext = ".AnyExtensionLength"

The problem with other suggestions:

1) "."s in Directory Name: "C:\Direct.ory\Ham\Cheese\FileName.ext"

2) Multiple "."s in filename: "This.is.my.file.name.bmp"

Edited by Harlequin
1 person likes this

But when a long train of abuses and usurpations, pursuing invariably the same Object evinces a design to reduce them under absolute Despotism, it is their right, it is their duty, to throw off such Government, and to provide new Guards for their future security. - U.S. Declaration of Independence

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