Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Deleting files using VBscript

Original Message
Name: NotForProfit
Date: April 27, 2005 at 15:37:39 Pacific
Subject: Deleting files using VBscript
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?


Report Offensive Message For Removal


Response Number 1
Name: NotForProfit
Date: April 27, 2005 at 15:53:38 Pacific
Subject: Deleting files using VBscript
Reply: (edit)
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?


Report Offensive Follow Up For Removal

Response Number 2
Name: StuartS
Date: April 27, 2005 at 17:26:58 Pacific
Subject: Deleting files using VBscript
Reply: (edit)
>>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


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: April 27, 2005 at 23:47:09 Pacific
Subject: Deleting files using VBscript
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 4
Name: StuartS
Date: April 28, 2005 at 06:42:36 Pacific
Subject: Deleting files using VBscript
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 5
Name: AleksG
Date: May 21, 2005 at 13:59:39 Pacific
Subject: Deleting files using VBscript
Reply: (edit)
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


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Deleting files using VBscript

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




acer 312T BIOS problem

K7 Turbo possible max fsb?

Pc anywher problem

WinFLP & OE/Outlook2003

Computer resets after a few minutes


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC