Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Accessing a: drive

Posted on 2000-04-02
14
Medium Priority
?
210 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 300 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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