Jump to content
Sign in to follow this  
crystalburner

String Splitting

Recommended Posts

crystalburner

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

Share this post


Link to post
Share on other sites
zatorg

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.

Share this post


Link to post
Share on other sites
Valuater

_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 extension

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
anixon

This is some code that I use in a File Selection Process

CODE
Case $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

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  

×