+ Reply to Thread
Results 1 to 4 of 4

Delete Directory Contents/DOS Shell

Hybrid View

Guest Delete Directory Contents/DOS... 03-17-2006, 07:10 PM
Guest Re: Delete Directory... 03-17-2006, 07:15 PM
Guest Re: Delete Directory... 03-17-2006, 07:15 PM
Guest RE: Delete Directory... 03-17-2006, 07:20 PM
  1. #1
    Edd
    Guest

    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. #2
    Chip Pearson
    Guest

    Re: 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" <Edd@discussions.microsoft.com> wrote in message
    news:EC99C6C1-9EA6-4929-A4D1-1F66658BC388@microsoft.com...
    > 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. #3
    Chip Pearson
    Guest

    Re: Delete Directory Contents/DOS Shell

    Or, shorter

    Kill "H:\test\*.*"



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


    "Edd" <Edd@discussions.microsoft.com> wrote in message
    news:EC99C6C1-9EA6-4929-A4D1-1F66658BC388@microsoft.com...
    > 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. #4
    Gary''s Student
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1