Solved

Accessing a: drive

Posted on 2000-04-02
14
207 Views
Last Modified: 2010-04-04
Hello,
How do I access drive a: or CDROM
drive and then automatically erase
files on that selected drive using
Delphi 5.
........................................
Ignore above I will rephrase question...
Senario: From a menu item I basically would need to wipe a disk
automatically...a Floppy in drive a:\ is a good example.
Please note by using filedelete()you have to know which files
are on disk and indivdually delete them.I would need an automated
approach.(Delete all files on drive a:).


regards,
frank
0
Comment
Question by:frw
[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
  • 3
  • 2
  • 2
  • +6
14 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 2678132
Erase files from CDROM????

Besides, I do not quite understand your question.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2678135
To delete files you can use this:

DeleteFile('A:\somefile.xxx');
0
 
LVL 17

Expert Comment

by:inthe
ID: 2678148
for a drive do exactly same as normal drive ..

deletefile(a:\somefilename.file)

you cant erase a file on cdrom unless you mean you have it formatted as a drive (like with easycd creator etc?)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:inthe
ID: 2678149
;-)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2678165
(o:
0
 

Author Comment

by:frw
ID: 2678485
Edited text of question.
0
 
LVL 15

Expert Comment

by:simonet
ID: 2678583
You have to do an interaction through all files in the disk in order to wipe the disk clean.

There are no functions in Delphi that will allow you to create a clean FAT on a floppy. You can use INT 21h functions, but that's a whole lotta trouble, and not sure to work with NT.

The best approach is to find all files on the disk, delete them as they are found. Then delete all directories and their parents, etc. Some interaction or recursion will be necessary here.

Yours,

Alex

0
 
LVL 1

Accepted Solution

by:
nrico earned 100 total points
ID: 2679314
simonet is right. I'll work it our for you... :-)

Function SlashDir(Name:String):String;
Begin
  If Name[Length(Name)]<>'\' Then Name:=Name+'\';
  SlashDir:=Name;
End;

Procedure WipeDir(Name:String);
Var
  S:TSearchRec;
  Result:Integer;
Begin
  Name:=SlashDir(Name);
  Result:=FindFirst(Name+'*.*',faAnyFile,S);
  While Result=0 Do
  Begin
    If (S.Attr Or faDirectory>0) And (S.Name[1]<>'.') Then WipeDir(Name+S.Name)
      Else DeleteFile(Name+S.Name);
    Result:=FindNext(S);
  End;
  FindClose(S);
  {$I-}
  RmDir(Name);
  {$I+}
End;

This could contain some minor bugs (Like I'm not sure about the TSearchRec.Attr member), but it should mostly be working.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2679456
uses ... ShellAPI;

.....
ShellExecute(handle,'open','command','/c DEL A:\YOURFILE.EXT',nil,0);
ShellExecute(handle,'open','command','/c DEL A:\*.EXE',nil,0);
....
--------
Igor.
0
 

Expert Comment

by:johnstoned
ID: 2679500
nrico's answer is the way i'd do it, but I think you need to change

If (S.Attr Or faDirectory>0) And (S.Name[1]<>'.') Then WipeDir(Name+S.Name)
      Else DeleteFile(Name+S.Name);


to

If (S.Attr and faDirectory>0) And (S.Name[1]<>'.') Then WipeDir(Name+S.Name)
      Else DeleteFile(Name+S.Name);

This will detect directories properly now.

Dave.
     
   
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2680701
You also need to change :

If (S.Attr and faDirectory>0) And (S.Name[1]<>'.') Then WipeDir(Name+S.Name)
      Else DeleteFile(Name+S.Name);

to

If (S.Attr and faDirectory>0) And (S.Name[1]<>'.') and (S.Name[1]<>'..') Then WipeDir(Name+S.Name)
      Else DeleteFile(Name+S.Name);


This will detect the parent directory when you are in a subdirectory.

0
 
LVL 1

Expert Comment

by:titz
ID: 2681128
hi,

i think the best and simplest way is to format the disc !

cheers
titz
0
 

Author Comment

by:frw
ID: 2682014
Thanks to all who got involved with
this question.
Frank
0
 
LVL 15

Expert Comment

by:simonet
ID: 2682534
Well, you're welcome.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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