Solved

Delete Hidden files

Posted on 2000-03-01
11
205 Views
Last Modified: 2010-04-04
When I use the DeleteFile(filename) function, it does not delete hidden files - so how can I do this?  I also remember a question about deleting files so they cannot be recoved by programs like the dos undelete.exe program, so could you help me on that?

Cheers
0
Comment
Question by:bogieman_
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 2

Accepted Solution

by:
aubs earned 100 total points
Comment Utility
Use the SetFileAttributes command before trying to delete the file.

SetFileAttributes(FileName, FILE_ATTRIBUTE_NORMAL);
0
 
LVL 1

Author Comment

by:bogieman_
Comment Utility
I want to remove many files at once as fast as possible - so does it take long to execute that command?
0
 
LVL 2

Expert Comment

by:aubs
Comment Utility
I've no idea!

Maybe you could try to using the deletefile command then only use SetFileAttributes if it fails.

Aubs
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
hi,
why not before the deletion make all files not hidden , then after deletion hide them again.
i can send example for this as i made a demo once for similar which does same as explorers dialog to show or hide files.
0
 

Expert Comment

by:skycrusher
Comment Utility

if the files are in the same directory,
maybe you can use this function:

BOOL RemoveDirectory(LPCTSTR lpszDir)

refer to Delphi's Help for more information about this function.

Regards,
skycrusher

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:akarasev
Comment Utility
You need to call Interrupt 21h Function 7141h. It must look like:

asm
 mov ax, 7141h    
 mov ch, 00h
 mov cl, 02h      
 mov dx, seg Filename      
 mov ds, dx
 mov dx, offset Filename
 mov si, 1  
 int 21h
end;

Regards.
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
asm dont work in nt ...
0
 
LVL 6

Expert Comment

by:Jaymol
Comment Utility
Yes it does!  I use it regulary!

John.
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
er ok it may work im mixed up between interupts and hardware ..

0
 
LVL 1

Author Comment

by:bogieman_
Comment Utility
I think I might just use aubs first suggestions - I am using a Tsearchrec to find certain files and delete them, so I can do this:

if (TheSearchRec.attr or fahidden >0) //I think that's right
then begin
SetFileAttributes(FileName, FILE_ATTRIBUTE_NORMAL);
deletefile(TheSearchRec.filename);
end else deletefile(filename);

But I havn't tested it
0
 
LVL 2

Expert Comment

by:aubs
Comment Utility
I think you mean:

if (TheSearchRec.attr AND faHidden >0) then
  SetFileAttributes(FileName, FILE_ATTRIBUTE_NORMAL);
Deletefile(Filename);  


Bear in mind that SearchRec.Name will only return the filename and extension - not the path!!!


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

8 Experts available now in Live!

Get 1:1 Help Now