Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Delete Hidden files

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
bogieman_
Asked:
bogieman_
  • 3
  • 3
  • 2
  • +3
1 Solution
 
aubsCommented:
Use the SetFileAttributes command before trying to delete the file.

SetFileAttributes(FileName, FILE_ATTRIBUTE_NORMAL);
0
 
bogieman_Author Commented:
I want to remove many files at once as fast as possible - so does it take long to execute that command?
0
 
aubsCommented:
I've no idea!

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

Aubs
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
intheCommented:
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
 
skycrusherCommented:

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
 
akarasevCommented:
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
 
intheCommented:
asm dont work in nt ...
0
 
JaymolCommented:
Yes it does!  I use it regulary!

John.
0
 
intheCommented:
er ok it may work im mixed up between interupts and hardware ..

0
 
bogieman_Author Commented:
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
 
aubsCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now