Solved

Delete Hidden files

Posted on 2000-03-01
11
214 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
ID: 2572950
Use the SetFileAttributes command before trying to delete the file.

SetFileAttributes(FileName, FILE_ATTRIBUTE_NORMAL);
0
 
LVL 1

Author Comment

by:bogieman_
ID: 2573117
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
ID: 2573420
I've no idea!

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

Aubs
0
Independent Software Vendors: 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: 2574841
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
ID: 2574883

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
 

Expert Comment

by:akarasev
ID: 2575159
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
ID: 2575846
asm dont work in nt ...
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2576070
Yes it does!  I use it regulary!

John.
0
 
LVL 17

Expert Comment

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

0
 
LVL 1

Author Comment

by:bogieman_
ID: 2580629
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
ID: 2596443
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

680 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