![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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? 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 Specs![]() |
| | #3 (permalink) |
| | 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 > ========== 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 Specs![]() |
| | #4 (permalink) |
| | 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 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 Specs![]() |
| | #5 (permalink) |
| | 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? 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 Specs![]() |
![]() |
| 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 | |||