crystalburner Posted May 6, 2007 Posted May 6, 2007 Hi guys If you have a string such as this c:\dir1\folder2\file name 1.doc c:\dir1\folder3\folder8\file name 2.doc How would you go about splitting the string in two so you had a foldername like so c:\dir1\folder2\ as string1 and a filename such as file name 1.doc as string2. I've got a bit stuck playing with string splits and so on... C
zatorg Posted May 6, 2007 Posted May 6, 2007 Dim $path = "C:\Documents and Settings\SomeUser\Desktop\some picture.jpg" Dim $filename = StringTrimLeft( $path, StringInStr( $path, "\", 0, -1 ) ) MsgBox( 64, "Filename", $filename )StringInStr ( "string", "substring" [, casesense [, occurrence]] )If occurence equals -1 then it returns the right-most occurence.StringTrimLeft ( "string", count )Returns the trimmed from the left string.
Valuater Posted May 6, 2007 Posted May 6, 2007 (edited) _PathSplit Splits a path into the drive, directory, file name and file extension parts. An empty string is set if a part is missing. #include <File.au3>_PathSplit ( $szPath, ByRef $szDrive, ByRef $szDir, ByRef $szFName, ByRef $szExt ) Parameters$szPath The path to be split (Can contain a UNC server or drive letter) $szDrive String to hold the drive $szDir String to hold the directory $szFName String to hold the file name $szExt String to hold the file extension8) Edited May 6, 2007 by Valuater
anixon Posted May 6, 2007 Posted May 6, 2007 This is some code that I use in a File Selection Process CODECase $msg = $selectfile GUIDelete() $csvfile = FileOpenDialog("Select a File", @ScriptDir & "\DataFiles\Pending", "All (*.*)", 1) Dim $szDrive, $szDir, $szFName, $szExt $splitcsv = _PathSplit($csvfile, $szDrive, $szDir, $szFName, $szExt) $Sfile = $szFName & $szExt If $csvfile = "" Then $message = " NO FILE Chosen" DisplayMessage() EndIf ExitLoop
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now