Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Delete Directory Contents/DOS Shell

Hi Experts:

I want to be able to delete the contents of a directory (or remove and
recreate the same directory). What is the best way to do that?

(My first thought is via a DOS shell using its commands, but I no not how
plus there has to be a better way.)

After I delete the contents of this directory, using data from a colum of a
spreadsheet, I would like to create a text file and copy that file to that
directory (the whose contents was deleted).

Your help is appreciated, please. Thanks!




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Delete Directory Contents/DOS Shell

Try the following code to delete all the files in a directory:

Dim FName As String

ChDrive "H:" '<<< CHANGE
ChDir "H:\Test" '<<< CHANGE

FName = Dir("*.*")
Do Until FName = ""
Kill FName
FName = Dir()
Loop



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Edd" wrote in message
...
Hi Experts:

I want to be able to delete the contents of a directory (or
remove and
recreate the same directory). What is the best way to do that?

(My first thought is via a DOS shell using its commands, but I
no not how
plus there has to be a better way.)

After I delete the contents of this directory, using data from
a colum of a
spreadsheet, I would like to create a text file and copy that
file to that
directory (the whose contents was deleted).

Your help is appreciated, please. Thanks!






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Delete Directory Contents/DOS Shell

Or, shorter

Kill "H:\test\*.*"



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Edd" wrote in message
...
Hi Experts:

I want to be able to delete the contents of a directory (or
remove and
recreate the same directory). What is the best way to do that?

(My first thought is via a DOS shell using its commands, but I
no not how
plus there has to be a better way.)

After I delete the contents of this directory, using data from
a colum of a
spreadsheet, I would like to create a text file and copy that
file to that
directory (the whose contents was deleted).

Your help is appreciated, please. Thanks!






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Delete Directory Contents/DOS Shell

What you are trying to do can be a little dangerous. The safest approach
might be to create a small .bat file, say dangerous.bat, and fully test it.
Then use SHELL to run the bat file:


Sub Macro1()
x = Shell("cmd.exe /c C:\belfry\dangerous.bat", 1)
End Sub

The danger is that if anything goes wrong with the CD commands in the bat
file, really bad things can happen.
--
Gary's Student


"Edd" wrote:

Hi Experts:

I want to be able to delete the contents of a directory (or remove and
recreate the same directory). What is the best way to do that?

(My first thought is via a DOS shell using its commands, but I no not how
plus there has to be a better way.)

After I delete the contents of this directory, using data from a colum of a
spreadsheet, I would like to create a text file and copy that file to that
directory (the whose contents was deleted).

Your help is appreciated, please. Thanks!




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Contents of a Directory Nigel Excel Programming 2 December 5th 05 05:57 PM
List the contents of a directory Diane Mallin[_2_] Excel Programming 3 February 24th 05 10:26 PM
Directory contents Eric[_6_] Excel Programming 1 August 27th 04 05:56 PM
Directory Contents Jo[_6_] Excel Programming 3 April 21st 04 03:19 AM
macro to move contents of directory Harvey[_3_] Excel Programming 0 February 9th 04 07:36 PM


All times are GMT +1. The time now is 06:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"