Computing.Net > Forums > Programming > Deleting files using VBscript

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Deleting files using VBscript

Reply to Message Icon

Name: NotForProfit
Date: April 27, 2005 at 15:37:39 Pacific
OS: Windows 2000
CPU/Ram: unknown
Comment:

I am writing a script to backup files to a USB drive. I would like to delete the old backup folder and all its files then rebuild and populate the folder. Everything works except the delete part. I have tried to use the following code:

Set oShell = CreateObject("WScript.Shell")

oShell.Run "command.com /C rd /s/q e:\backup"

oShell.Run "command.com /C mkdir e:\backup"

the mkdir command works fine but the rd command does not work. Did they disable the abliity to delete files and directories in this way to make VBscript more secure. If so how could I make it work?



Sponsored Link
Ads by Google

Response Number 1
Name: NotForProfit
Date: April 27, 2005 at 15:53:38 Pacific
Reply:

I actually found a solution in the forums posted by dtech

Set fso=CreateObject("Scripting.FileSystemObject")
CleanPath="I:\Test\"

For Each file In fso.GetFolder(CleanPath).Files
file.delete
Next

I am still curious as to why none of the delete commands built into command.com seem to work from vbscript, were they disabled to increase security?


0

Response Number 2
Name: StuartS
Date: April 27, 2005 at 17:26:58 Pacific
Reply:

>>I am still curious as to why none of the delete commands built into command.com seem to work from vbscript <<

Becasue Command.com is a DOS programme. VBScript is a Windows utility.


Stuart


0

Response Number 3
Name: Mechanix2Go
Date: April 27, 2005 at 23:47:09 Pacific
Reply:

Stuart,

Yes, but in w2k both command.com and cmd.exe support rd /s/q

M2


If at first you don't succeed, you're about average.


0

Response Number 4
Name: StuartS
Date: April 28, 2005 at 06:42:36 Pacific
Reply:

So they do as do all versions of Windows. But by the time command.com is loaded under 2000/XP you are running under a DOS emulator.

Visual Basic will run DOS commands but VB Script is not that sophisticated.

Stuart


0

Response Number 5
Name: AleksG
Date: May 21, 2005 at 13:59:39 Pacific
Reply:

In Java I managed to delete folder by using
cmd /C rd /S /Q my_folder
It may also work in VBscript


CCB for life


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Deleting files using VBscript

backing up log files using vbscript www.computing.net/answers/programming/backing-up-log-files-using-vbscript/9220.html

WSH: Delete files in folder by date www.computing.net/answers/programming/wsh-delete-files-in-folder-by-date/16255.html

deleting folders - use batch prog www.computing.net/answers/programming/deleting-folders-use-batch-prog/11998.html