Sign in to follow this  
Followers 0
shayneh

Get Filename And Path From A Pathfilename Spec

8 posts in this topic

#1 ·  Posted (edited)

I would like to get the path and filename from a pathfilename spec that doesn't necessarily exist on the file system.

In vb script:

Set fso = CreateObject("Scripting.FileSystemObject")
   file = fso.GetFileName(pathfilename)

How can this be done in AutoIt3?

Thanks,

ShayneH

Edited by shayneh

Share this post


Link to post
Share on other sites



Umm, I'm not sure what exactly the Scripting.FileSystemObject.GetFileName does. I'm guessing it gives you the filename suchas "text.txt" and the path might be "c:\program files". Try something like

$file = "c:\Path\To\The\File.txt"
$file = StringSplit($file, "\")
$path = ""
For $i = 1 To $file[0] - 1
$path = $path & $file[$i] & "\"
next
$filename = $file[$file[0]]
msgbox(0,'',$path & $filename)

Or you can use the same object approach you've been using

$fso = ObjCreate("Scripting.FileSystemObject")
$a = $fso.GetFileName($SomeVariableHoldingTheFile)

~cdkid


AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

Thanks

Share this post


Link to post
Share on other sites

$filepath = "c:\Path\To\The\File.txt"

$file = StringTrimLeft($filepath,StringInStr($filepath,"\",0,-1))

Pure Genius Larry! I've always used:

$ShortFilePathArray = StringSplit($FilePath,"\")
$ShortFilePath = _ArrayPop($ShortFilePathArray)

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

$filepath = "c:\Path\To\The\File.txt"

$file = StringTrimLeft($filepath,StringInStr($filepath,"\",0,-1))

Nice and short and efficiant.

How can I get only the path like this?

Share this post


Link to post
Share on other sites

Nice and short and efficiant.

How can I get only the path like this?

$filepath = "c:\Path\To\The\File.txt"
$file = StringTrimLeft($filepath,StringInStr($filepath,"\",0,-1))
$Path = StringLeft($filepath,StringInStr($filepath,"\",0,-1)-1)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

$filepath = "c:\Path\To\The\File.txt"
$file = StringTrimLeft($filepath,StringInStr($filepath,"\",0,-1))
$Path = StringLeft($filepath,StringInStr($filepath,"\",0,-1)-1)
:) Thanks a lot

Was making thing to complicated by lack of knowledge of all the possible commands.

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