Ermitteln, wann Datei fertig geschrieben wurde

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

TheProgrammer

Betreff: Ermitteln, wann Datei fertig geschrieben wurde

BeitragSo, Jul 08, 2007 14:18
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi,

ich habe ein Programm, welches Dateien manipulieren soll, sobald sie von einem anderen Programm erstellt werden. Dazu hält das Programm immer ausschau nach neuen Dateien in einem bestimmten Ordner. Es findet die Dateien jedoch schon, obwohl sie noch nicht fertig geschrieben wurden. (In meinem Fall wmv-Dateien)
Kann ich irgendwie ermitteln, ob die Dateien schon abgeschlossen wurden? Ich habe schon versucht, durch FileSize() zu prüfen, ob sie schon Daten beinhalten. Jedoch funktioniert das nicht.
Ich hoffe, ihr könnt mir da irgendwie helfen. Würde mich über schnelles Feedback sehr freuen. Wink

Mfg
TheProgrammer
aktuelles Projekt: The last day of human being

Puccini

BeitragSo, Jul 08, 2007 15:25
Antworten mit Zitat
Benutzer-Profile anzeigen
ich bin auf die funktion ReadAvail(stream) gestossen!

damit kannste auslesen wieviel byte die datei beinhaltet!

da könntest du doch in deinem prog ne abfrage machen:

wenn sich readavail innerhalb von 10sec nicht ändert dann scheint datei vollständig zu sein

oder so in der art??? weis ja net wie schnell die daten in die wmv datei geschrieben werden??
-=Achtung=-
Suche Hobby-Modelliere der hin und wieder bock hat ein kleines Objekt zu erstellen. Bei Interesse PM
www.ragesoft.de
Passwortmanager: http://ragesoft.de/index.php?o...;Itemid=39

ZaP

BeitragSo, Jul 08, 2007 15:28
Antworten mit Zitat
Benutzer-Profile anzeigen
Oder du schreibst ans ende der Datei einen String wie "%%FILE_END%%" an dem deine App erkennt dass die Datei da aufhört, und beim einlesen lässt du die Zeile halt aus.
Starfare: Worklog, Website (download)

TheProgrammer

BeitragSo, Jul 08, 2007 15:52
Antworten mit Zitat
Benutzer-Profile anzeigen
@ZaP: Ich habe ja keinen Einfluss auf die Dateien, da sie von einem Videobearbeitungsprogramm geschrieben werden.. ^^

@Puccini: Thx, jedoch finde ich diese Methode ziemlich ungenau.

Wäre toll, wenn es da eine Möglichkeit gäbe, mit der man ganz genau bestimmen kann, wann die Datei fertig geschrieben wurde.
aktuelles Projekt: The last day of human being
 

ByteCroc

BeitragSo, Jul 08, 2007 16:11
Antworten mit Zitat
Benutzer-Profile anzeigen
Evtl. ist das die richtige für dich

FindFirstChangeNotification

TheProgrammer

BeitragSo, Jul 08, 2007 16:38
Antworten mit Zitat
Benutzer-Profile anzeigen
Vielen Dank. Smile

Hättest vlt. noch erwähnen können, dass das aus der kernel32.dll ist.. ^^

Code: [AUSKLAPPEN]
.lib "kernel32.dll"

api_FindFirstChangeNotification% (lpPathName$, bWatchSubtree%, dwNotifyFilter%) : "FindFirstChangeNotificationA"


Leider weiß ich jetzt nicht, wie ich den befehl anwenden kann..

http://search.msdn.microsoft.c...lang=de-de
...hilft mir da leider auch nicht viel weiter.

Mfg
TheProgrammer
aktuelles Projekt: The last day of human being
 

ByteCroc

BeitragSo, Jul 08, 2007 16:51
Antworten mit Zitat
Benutzer-Profile anzeigen
Soory ich dachte du hast eine Api Referenz auf der Platte, da gibts einen Index, vielleicht find ich den Link noch, ich editiers dann unten ran
vielleicht helfen solange diese Seiten

http://runtime-basic.net/doku....indows-API
http://runtime-basic.net/doku....:ApiHelper

und die Kopie meiner Seite

Code: [AUSKLAPPEN]

The FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle succeeds when a change matching the filter conditions occurs in the specified directory or subtree.

HANDLE FindFirstChangeNotification(

    LPCTSTR lpPathName,   // pointer to name of directory to watch 
    BOOL bWatchSubtree,   // flag for monitoring directory or directory tree 
    DWORD dwNotifyFilter    // filter conditions to watch for
   );   
 

Parameters

lpPathName

Points to a null-terminated string that specifies the path of the directory to watch.

bWatchSubtree

Specifies whether the function will monitor the directory or the directory tree. If this parameter is TRUE, the function monitors the directory tree rooted at the specified directory; if it is FALSE, it monitors only the specified directory.

dwNotifyFilter

Specifies the filter conditions that satisfy a change notification wait. This parameter can be one or more of the following values:

Value   Meaning
FILE_NOTIFY_CHANGE_FILE_NAME   
Any filename change in the watched directory or subtree causes a change notification wait operation to return. Changes include renaming, creating, or deleting a filename.
FILE_NOTIFY_CHANGE_DIR_NAME   
Any directory-name change in the watched directory or subtree causes a change notification wait operation to return. Changes include creating or deleting a directory.
FILE_NOTIFY_CHANGE_ATTRIBUTES   
Any attribute change in the watched directory or subtree causes a change notification wait operation to return.
FILE_NOTIFY_CHANGE_SIZE   
Any file-size change in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change in file size only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.
FILE_NOTIFY_CHANGE_LAST_WRITE   
Any change to the last write-time of files in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change to the last write-time only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.
FILE_NOTIFY_CHANGE_SECURITY   
Any security-descriptor change in the watched directory or subtree causes a change notification wait operation to return.
 

Return Values

If the function succeeds, the return value is a handle to a find change notification object.
If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.

Remarks

The wait functions can monitor the specified directory or subtree by using the handle returned by the FindFirstChangeNotification function. A wait is satisfied when one of the filter conditions occurs in the monitored directory or subtree.
After the wait has been satisfied, the application can respond to this condition and continue monitoring the directory by calling the FindNextChangeNotification function and the appropriate wait function. When the handle is no longer needed, it can be closed by using the FindCloseChangeNotification function.

See Also

FindCloseChangeNotification, FindNextChangeNotification


FindCloseChangeNotification, FindNextChangeNotification brauchst du auch noch

Edit:
Hier der Link zur Downloadversion
http://www.powerbasic.com/files/pub/docs/Win32.zip
 

Krümel

BeitragMi, Jul 11, 2007 0:02
Antworten mit Zitat
Benutzer-Profile anzeigen
Etwas in der Art habe ich schonmal geschrieben.
Kannst du ja mal testen...

Das hier in die USERLIB, z.B. "KERNEL32.DECLS"
Code: [AUSKLAPPEN]

.lib "Kernel32.dll"
CreateFile%(lpFileName$,dwDesiredAccess%,dwShareMode%,lpSecurityAttributes%,dwCreationDispostion%,dwFlagsAndAttributes%,hTemplateFile%):"CreateFileA"
CloseHandle%(hFile%):"CloseHandle"
FindFirstFile%(lpFileName$,lpFindFileData*):"FindFirstFileA"
FindClose%(hFindFile%):"FindClose"


Hier der Code:
Code: [AUSKLAPPEN]

Const GENERIC_READ% = $80000000
Const OPEN_EXISTING% = 3
Const FILE_ATTRIBUTE_NORMAL% = $80

Function IsFileInUse(sFile$)
   WIN32_FIND_DATA = CreateBank(512)

   If FileExists(sFile , WIN32_FIND_DATA) Then
      hFile = CreateFile(sFile,GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0)
      CloseHandle hFile

      If hFile = -1
         Print "File is in use"      
      Else
         Print "File is available"      
      EndIf
   Else
      Print "File does not exist!"
   EndIf
   FreeBank WIN32_FIND_DATA
End Function

Function FileExists(sSource$ , bank%)
   hFile = FindFirstFile(sSource, bank)
   FindClose(hFile)
      
   Return hFile <> -1
End Function


Das hier dient nur zum Testen der Funktion:
Code: [AUSKLAPPEN]

;Datei erstellen
testFile=WriteFile("c:\test.txt")

;1. Test - sollte "File is in use" zurückgeben
IsFileInUse("c:\test.txt")

;Datei schliessen
CloseFile testFile

;2. Test - sollte "File is available" zurückgeben
IsFileInUse("c:\test.txt")

;Datei löschen
DeleteFile ("c:\test.txt")

;3. Test - sollte "File does not exist!" zurückgeben
IsFileInUse("c:\test.txt")

[/code]


Viele Grüße,
Krümel

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group