?
Solved

Deleting a File in disk using partial search

Posted on 2003-03-08
5
Medium Priority
?
196 Views
Last Modified: 2010-04-04
hi,

I want to delete all files with the substring Salesxx
for instance SalesxxWed092003,SalesxxTue032003, from my disk(c),

hint: Ability to do a partial match

please Assist...
0
Comment
Question by:Muthenya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Accepted Solution

by:
steve_hsk earned 176 total points
ID: 8093585
Hi Muthenya ...

There are two parts to your problem :-
1. Find the files you want to delete,
2. Deleting these files to the Recycle Bin.

Due to the ease of being able to delete your entire hard-drive in seconds, I would suggest finding the necessary files first, displaying these files, checking they're correct, and finally deleting them to the Recycle bin so they can be emyptied or restored at a later date.

Part 1:
Finding the files can be written yourself, or done very easily by using one the following components, which include source code, use of wildcards for partial matches, recursive searches for sub-folders etcetc :
http://www.torry.net/search.htm

** This is not a complex task if broken down neatly ;-)

The partial search is normally undertaken by putting a wrapper around TSearchRec, and the undocumented IsWild function, defined in StrUtils.Pas

Part 2:
Deleting the files to the Recycle bin : code snippet for ya :

uses ShellApi, etc, etc ...

procedure TBtchOp_Delete.SendToRecycleBin (FileName: string);
var
  SHF: TSHFileOpStruct;
begin
  with SHF do begin
    Wnd := Application.Handle;
    wFunc := FO_DELETE;
    pFrom := PChar(FileName);
    fFlags := FOF_SILENT or FOF_ALLOWUNDO;
  end;
  SHFileOperation(SHF);
end;

PS : I use TFileFinder.Pas by William Yang (his homepage no lopnger exists, but if you can't find this on the web-I'll email it to you)

Hope this helps,
Steve
0
 
LVL 5

Assisted Solution

by:Lukasz Lach
Lukasz Lach earned 172 total points
ID: 8093658
procedure DeleteMatch(const dir, path, name: String);
var
        SR : TSearchRec;
        Found : Integer;
        source : String;
begin
        source := dir + path;
        Found := FindFirst(source+'\'+name, faAnyFile, SR );
        try
                while  (Found = 0)  do
                begin
                        if (SR.Name<>'.') and (SR.Name <> '..') then
                        begin
                                if (SR.Attr and faDirectory) <> 0 then
                                    DeleteMatch( dir, path+'\'+SR.Name )
                                else
                                begin
                                        FileSetAttr(
                                        source+'\'+SR.Name, FileGetAttr(source+'\'+SR.Name)
                                        and
                                        not (faReadOnly or faHidden) );
                                        DeleteFile( PChar(source+'\'+SR.Name) )
                                end;
                        end;
                        Found := FindNext( SR );
                end;
        finally
                Sysutils.FindClose(SR);
        end;
end;

use:
DeleteMatch('C:\', '', 'sales??Wed092003.*');
0
 

Expert Comment

by:CleanupPing
ID: 9316889
Muthenya:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 10090409
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

Split between steve_hsk and anAKiN

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 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