Jump to content

How can I delete a relative parent folder using vbs?


Recommended Posts


No guarantee that this would work because the script will be in use, but if it does work, this would do it:

Dim FSO
Dim FolderPath

Set FSO = CreateObject("Scripting.FileSystemObject")
FolderPath = FSO.GetParentFolderName(WScript.ScriptFullName)
FSO.DeleteFolder FolderPath, True
Set FSO = Nothing

Link to comment
Share on other sites

No guarantee that this would work because the script will be in use, but if it does work, this would do it:

Dim FSO
Dim FolderPath

Set FSO = CreateObject("Scripting.FileSystemObject")
FolderPath = FSO.GetParentFolderName(WScript.ScriptFullName)
FSO.DeleteFolder FolderPath, True
Set FSO = Nothing

Is there a way the script can be stored in a temporary location just before execution, so that the folder is not locked while its execution?

Do you think batch commands can do it?

Edited by srk999
Link to comment
Share on other sites

As stated above the following will work:

Set oFS = CreateObject("Scripting.FileSystemObject")
MyParent = oFS.GetParentFolderName(WScript.ScriptFullName)
oFS.DeleteFolder MyParent, True

Just make the bottom line the last one in your VBScript.

The following batch file will work fine too:

ntscript.cmd

@Set "C_=X:\MyDir\New\some.vbs"
@For %%# In (%C_%) Do @Set "P_=%%~dp#"&@%C_%&&@Rd/s/q "%P_%"

If you wish you could run your vbs using '@cscript //nologo %C_%' too!

Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...