Solved

Delete *.* - Simple Question

Posted on 1999-01-09
4
202 Views
Last Modified: 2010-04-06
DeleteFile function deletes a specific file in at a given address.

What command or procedure could I use to delete all the files in a specific directory. i.e. Dos del*.*
0
Comment
Question by:smithsj1
  • 2
4 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1355501
Hmmm. With subdirectories or without?
You could either write a simple recursive loop with FindFirstFile, FindNextFile, FindClose. Then delete all files with DeleteFile (perhaps calling SetFileAttributes to disable write protection) and RemoveDirectory.
Or you could call a DOS command in hidden state (I could give you some sources for that).

Regards, Madshi.
0
 
LVL 1

Accepted Solution

by:
adeng earned 30 total points
ID: 1355502
1. Make a Form with Edit Box for directory name.

procedure TForm1.Button1Click(Sender: TObject);
var
     SearchRec: TSearchRec;
     I, M     : Integer;
begin
          M := FindFirst(Edit1.Text + '\*.*', 0, SearchRec);
          while M = 0 do
          begin
               DeleteFile(SearchRec.name);
               M := FindNext(SearchRec);
          end;
end;

Adeng
0
 
LVL 1

Expert Comment

by:adeng
ID: 1355503
Found on Delphi Help


Unit

SysUtils

Category

File management routines
FindFirst searches for the first instance of a file name with a given set of attributes in a specified directory.

function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer;

Description

FindFirst searches the directory specified by Path for the first file that matches the file name implied by Path and the attributes specified by the Attr parameter. The result is returned in the F parameter. Use the fields of this search record to extract the information needed. FileFirst returns 0 if a file was successfully located, otherwise, it returns a Windows error code.
The Path constant parameter is the directory and file name mask, including wildcard characters. For example, 'c:\test\*.*' specifies all files in the C:\TEST directory).

The Attr parameter specifies the special files to include in addition to all normal files. Choose from these file attribute constants when specifying the Attr parameter:

Constant      Value      Description
faReadOnly      $00000001      Read-only files
faHidden      $00000002      Hidden files
faSysFile      $00000004      System files
faVolumeID      $00000008      Volume ID files
faDirectory      $00000010      Directory files
faArchive      $00000020      Archive files
faAnyFile      $0000003F      Any file
Attributes can be combined by adding their constants or values. For example, to search for read-only and hidden files in addition to normal files, pass (faReadOnly + faHidden) the Attr parameter.

Note

The FindFirst function allocates resources (memory) which must be released by calling FindClose.

Example

FindFirst is typically used in conjunction with FindNext and FindClose as follows, where ProcessSearchRec represents user-defined code that processes the information in a search record:

begin

    Found := FindFirst(Path, Attr, SearchRec);
    while Found = 0 do
    begin
      ProcessSearchRec(SearchRec);
      Found := FindNext(SearchRec);
    end;
    FindClose(SearchRec);
end;
0
 

Author Comment

by:smithsj1
ID: 1355504
Madshi

What i've got is a database program which when opened creates about 10 temp.db tables in c:\temp\analysis.

What I want to do is simply delete all the files in the c:\temp\analysis folder when the form is closed. There is not need to remove the directory.

Tables are created with table1.createtable so no attributes are attached.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now