Help - Search - Members - Calendar
Full Version: How can I delete a relative parent folder using vbs?
MSFN Forums > Coding, Scripting and Servers > Programming (C++, Delphi, VB, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
srk999
I need to delete the parent folder that the vbs script is in. For example, if the vbs script is in the folder "New", I need to delete the folder with everything in it using the script.
jcarle
No guarantee that this would work because the script will be in use, but if it does work, this would do it:

CODE
Dim FSO
Dim FolderPath

Set FSO = CreateObject("Scripting.FileSystemObject")
FolderPath = FSO.GetParentFolderName(WScript.ScriptFullName)
FSO.DeleteFolder FolderPath, True
Set FSO = Nothing
srk999
QUOTE (jcarle @ Aug 28 2008, 02:44 AM) *
No guarantee that this would work because the script will be in use, but if it does work, this would do it:

CODE
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?
Yzöwl
As stated above the following will work:
CODE
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
CODE
@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!
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.