Jump to content

Recommended Posts

Posted

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??? :)

Posted

#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

Posted (edited)

quicker solution

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

Cheers,FireFox.

Edited by FireFox
Posted

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.
Posted (edited)

@Andreik

If you insist :)

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

Cheers, FireFox.

Edited by FireFox
Posted

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]
Posted

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

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

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

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

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...