Prüfen, ob Datei bereits geöffnet ist

MAN

Erfahrenes Mitglied
Hallo,

wie kann ich denn prüfen, ob ein anderes Programm eine gewisse Datei geöffnet hat?

Habe es mit folgenden Code versucht:

Code:
bool FileIsOpen( string strFileName )
{
	FILE* fp;
	
	if( ( fp = fopen( strFileName.data(), "r" ) ) )
	{
		fclose( fp );
		
		return( false );
	}

	return( true );
}
Warum funktioniert das nicht?
Er meint IMMER dass die Datei nicht offen ist, obwohl ich sie mit nem andren Programm auf jeden Fall offen hab (da ich auch versucht hatte die Datei zu dem Zeitpunkt zu löschen - ging nicht).

Was mache ich falsch?

mfG

MAN
 
Ich glaube so wie du es versuchst, können mehrer Programme die Datei zum Lesen öffnen 'r'
daher gibt es kein Problem beim öffnen.
Du mußt einen anderen Modus beim Öffnen wählen (Exclusive oder so)
Weiß aber gerade nicht den nötigen Parameter
Lies in der Doku von fopen nach.
Probier auch einfach mal 'w' für write, vielleicht genügt das schon
vop
 
Tjo..... was soll ich denn da nehmen?

"r"

Opens for reading. If the file does not exist or cannot be found, the fopen call fails.

"w"

Opens an empty file for writing. If the given file exists, its contents are destroyed.

"a"

Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn‚t exist.

"r+"

Opens for both reading and writing. (The file must exist.)

"w+"

Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.

"a+"

Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn‚t exist.

ich kann irgendwie sogar in die datei reinschreiben, obwohl sie vom andren progrramm geöffnet ist! Jedoch kann ich sie trotzdem nich löschen..... irgendwie unlogisch....

Gibt es nicht ne andre Möglichkeit?

mfG

MAN
 
Zurück