Solved

Accessing a: drive

Posted on 2000-04-02
14
203 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
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating threads in delphi 1 101
SUM 2 INTEGER ARRAYS INTO 1 10 100
TEMBEDDEDWB how can i change its user agent ? 8 55
Not able to call Delphi XE10 dll function from Delphi 6.0 4 26
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

11 Experts available now in Live!

Get 1:1 Help Now