Get the App
SLTechnology News&Howtos  ›  Development  › 

The use of GetParentFolderName method in VBS

Shulou Source: shulou.com Published: 2022-06-03 19:37:58 11月12日 Update

This article focuses on "the use of GetParentFolderName method in VBS". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "the use of GetParentFolderName method in VBS"!

GetParentFolderName method

Returns a string containing the parent folder of the last file or folder in the specified path.

Object.GetParentFolderName (path)

Parameters.

Object

Required. Should be the name of FileSystemObject.

Path

Required. Specify the path to return the parent folder name of the file or folder.

Description

If the file or folder specified by the path parameter has no parent folder, the GetParentFolderName method returns a zero-length string (").

The following example illustrates how to use the GetParentFolderName method:

Function GetTheParent (DriveSpec) Dim fsoSet fso = CreateObject ("Scripting.FileSystemObject") GetTheParent = fso.GetParentFolderName (Drivespec) End Function

Note that the GetParentFolderName method only works on strings that provide path. It cannot attempt to analyze a path, nor can it check whether the specified path exists.

For more details, please refer to this article: https://www.jb51.net/shouce/vbs/vsmthGetParentFolderName.htm

Let me share one with you.

VBS script recursively creates a multi-level (hierarchical) directory folder

CreateFolders "d:\ ftptest\ 1\ 2\ 3\ 4\ 5" Function CreateFolders (path) Set fso = CreateObject ("scripting.filesystemobject") CreateFolderEx fso,path set fso = NothingEnd FunctionFunction CreateFolderEx (fso,path) If fso.FolderExists (path) Then Exit Function End If If Not fso.FolderExists (fso.GetParentFolderName (path)) Then CreateFolderEx fso,fso.GetParentFolderName (path) End If fso.CreateFolder (path) End Function

It mainly uses the principle of recursive call to achieve step-by-step directory creation.

At this point, I believe you have a deeper understanding of "the use of the GetParentFolderName method in VBS". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: File method folder character string path content parameter directory recursion learning practical deeper function example interest principle name practicality practice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information Docker Microsoft vpn