Solved

Accessing a: drive

Posted on 2000-04-02
14
200 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
  • 3
  • 2
  • 2
  • +6
14 Comments
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
Erase files from CDROM????

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

Expert Comment

by:Epsylon
Comment Utility
To delete files you can use this:

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

Expert Comment

by:inthe
Comment Utility
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
 
LVL 17

Expert Comment

by:inthe
Comment Utility
;-)
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
(o:
0
 

Author Comment

by:frw
Comment Utility
Edited text of question.
0
 
LVL 15

Expert Comment

by:simonet
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Accepted Solution

by:
nrico earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
hi,

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

cheers
titz
0
 

Author Comment

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

Expert Comment

by:simonet
Comment Utility
Well, you're welcome.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

12 Experts available now in Live!

Get 1:1 Help Now