Article View: borland.public.cppbuilder.nativeapi
Article #14484Directory in use after FindFirstFile ?!
From: ScOe
Date: Tue, 12 Aug 2003 10:37
Date: Tue, 12 Aug 2003 10:37
77 lines
3558 bytes
3558 bytes
Does the FindClose release any connection to directory ?
I have certain problem ... when i start this application it scans directory
tree and delete unwanted files.
After that process i cant delete manualy (from explorer) any directory from
that tree untill i close application.
Error message is that directory is in use ...
code snipet:
void TForm1::FindFilesInDirectory (const String directory, const String
extenzion)
{
String Ext = extenzion;
int Cpos=0;
Cpos = extenzion.Pos(";");
int z=1;
if (!extenzion.Pos(";"))
FindExtension(directory, Ext);
else {
do {
if (z == Cpos) {
FindExtension (directory,Ext.SubString(1,z-1));
Ext.Delete(1,z);
Cpos = Ext.Pos(";");
z=1;
}
else {
if (z == Ext.Length())
FindExtension (directory,Ext.SubString(1,z));
}
z++;
} while (z!='/0');
}
//
WIN32_FIND_DATA filedata ; // Structure for file data
HANDLE filehandle ; // Handle for searching
String dir = directory + "*.*" ;
filehandle = FindFirstFile ((directory + "*.*").c_str (), &filedata) ;
if (filehandle != INVALID_HANDLE_VALUE) {
do {
if ((filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0
&& String (filedata.cFileName) != "."
&& String (filedata.cFileName) != "..") {
FindFilesInDirectory (directory + filedata.cFileName + "\\",
extenzion) ;
}
Application->ProcessMessages () ;
} while (FindNextFile (filehandle, &filedata)) ;
FindClose (filehandle) ;
}
if (filehandle)
FindClose (filehandle) ;
Application->ProcessMessages () ;
}
//---------------------------------------------------------------------
void TForm1::FindExtension (const String path, const String extension)
{
WIN32_FIND_DATA filedata ; // Structure for file data
HANDLE filehandle ; // Handle for searching
TListItem *li;
filehandle = FindFirstFile ((path + extension).c_str (), &filedata) ;
if (filehandle != INVALID_HANDLE_VALUE) {
do {
if (filedata.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) {
li = ListView1->Items->Add () ;
li->Caption = path + filedata.cFileName ;
li->SubItems->Add (String (filedata.cAlternateFileName)) ;
Application->ProcessMessages () ;
}
} while (FindNextFile (filehandle, &filedata)) ;
FindClose (filehandle) ;
}
if (filehandle)
FindClose (filehandle) ;
}
Technical Details
Message-ID:
<3f38c3b7@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!demon!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,7baaff1b6531e4d0,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-12 03:40:01 PST From: "ScOe" <sven.savic@zg.hinet.hr> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Directory in use after FindFirstFile ?! Date: Tue, 12 Aug 2003 12:37:37 +0200 Lines: 80 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300 NNTP-Posting-Host: 213.191.148.209 Message-ID: <3f38c3b7@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1060684727 213.191.148.209 (12 Aug 2003 03:38:47 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!demon!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail