Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Extracting drive, path filebasename or extension from complete filename?

Reply
 
Old 03-29-2009   #1 (permalink)
Thomas Lebrecht


 
 

Extracting drive, path filebasename or extension from complete filename?

Assume I have a full filename like

myfile="D:\aaa\bbb\ccc\ddd.txt"

How can I extract the individual parts (drive, path, filenbase and extension) from it?

How do I get the path and filenam of the current vbs script from inside this script?

Thomas


My System SpecsSystem Spec
Old 03-29-2009   #2 (permalink)
Armin Zingler


 
 

Re: Extracting drive, path filebasename or extension from complete filename?

"Thomas Lebrecht" <t.lebrecht@xxxxxx> schrieb
Quote:

> Assume I have a full filename like
>
> myfile="D:\aaa\bbb\ccc\ddd.txt"
>
> How can I extract the individual parts (drive, path, filenbase and
> extension) from it?
>
> How do I get the path and filenam of the current vbs script from inside
> this script?
See

System.IO.Path.Get*

methods.

If you like a different answer, don't post to the VB.Net group
(m.p.dotnet.languages.vb)


Armin

My System SpecsSystem Spec
Old 03-29-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Extracting drive, path filebasename or extension from complete filename?


"Thomas Lebrecht" <t.lebrecht@xxxxxx> wrote in message
news:49cf8e9c$0$31869$9b4e6d93@xxxxxx-online.net...
Quote:

> Assume I have a full filename like
>
> myfile="D:\aaa\bbb\ccc\ddd.txt"
>
> How can I extract the individual parts (drive, path, filenbase and
> extension) from it?
>
> How do I get the path and filenam of the current vbs script from inside
> this script?
>
> Thomas
>
In VBScript use the FileSystemObject. For example:
==========
Option Explicit

Dim strFile, objFSO, objFile, objFolder
Dim strFileName, intIndex

strFile = "D:\aaa\bbb\ccc\ddd.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strFile)
Set objFolder = objFile.ParentFolder

Wscript.Echo "Name: " & objFile.Name
Wscript.Echo "ParentFolder: " & objFile.ParentFolder
Wscript.Echo "Path: " & objFile.Path
Wscript.Echo "Type: " & objFile.Type
Wscript.Echo "Parent Folder: " & objFolder.Name
Wscript.Echo "Drive: " & objFolder.Drive
Wscript.Echo "Parent Folder Path: " & objFolder.Path
strFileName = objFile.Name
intIndex = InStr(strFileName, ".")
If (intIndex > 0) Then
Wscript.Echo "File Extension: " & Mid(strFilename, intIndex + 1)
Else
Wscript.Echo "File Extension: "
End If
========
You have to parse for the extension, as above. You can also use WMI to
retrieve this information.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 03-29-2009   #4 (permalink)
Onur Güzel


 
 

Re: Extracting drive, path filebasename or extension from completefilename?

On Mar 29, 6:07*pm, t.lebre...@xxxxxx (Thomas Lebrecht) wrote:
Quote:

> Assume I have a full filename like
>
> myfile="D:\aaa\bbb\ccc\ddd.txt"
>
> How can I extract the individual parts (drive, path, filenbase and extension) from it?
>
> How do I get the path and filenam of the current vbs script from inside this script?
>
> Thomas
In VB.NET (because it seems posted here):

Dim path As String = "D:\aaa\bbb\ccc\ddd.txt"

' To get Drive letter
System.IO.Path.GetPathRoot(path)

' To get whole path
System.IO.Path.GetFullPath(path)

' To get extension
System.IO.Path.GetExtension(path)

'...more on System.IO.Path as previously said.

HTH,

Onur Güzel

My System SpecsSystem Spec
Old 03-29-2009   #5 (permalink)
Paul Randall


 
 

Re: Extracting drive, path filebasename or extension from complete filename?


"Thomas Lebrecht" <t.lebrecht@xxxxxx> wrote in message
news:49cf8e9c$0$31869$9b4e6d93@xxxxxx-online.net...
Quote:

> Assume I have a full filename like
>
> myfile="D:\aaa\bbb\ccc\ddd.txt"
>
> How can I extract the individual parts (drive, path, filenbase and
> extension) from it?
>
> How do I get the path and filenam of the current vbs script from inside
> this script?
Microsoft has a free downloadable scripting help file, script56.chm; it is
installed by default with most recent OSs. This help file covers VBScript
and JScript and also talks about a few of the common Microsoft objects
typically used by scripters, such as the file system object (FSO). The FSO
does include tools (methods) to get at the "individual parts (drive, path,
filenbase and extension)". These methods parse a string representing an
imaginary path; they don't care whether the path actually exists or not.
The names of most (maybe all) of these path-parsing methods have the
following format: Get...Name, where ... indicates the name of the part of
the path that you want. In the Index tab of the help file, type the word
'get' to see a list of topics that start with the three characters 'get'.

-Paul Randall


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Extracting drive, path, filebasename WITH string functions and NOT system function ??? VB Script
How to set a limit on Filename Path .NET General
Opening a file of known path but different extension VB Script
Parsing path and filename PowerShell
full path versus ./filename PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46