Вниз
Скачать: CL | DM;

Ошибка: "Cannot open file ..."   Найти похожие ветки 

 
Andy BitOff ©   (2005-06-07 10:58) [0]

Ситация такая, передаю по сети файл, файл является вордовским документом и если он открыт в ворде, то при;

IDClient.Socket.WriteBufferOpen();
IDClient.Socket.WriteFile("SomeFile");
IDClient.Socket.WriteBufferClose;

На WriteFile вываливается ошибка: "Cannot open file "SomeFile". Пpoцecc нe мoжeт пoлyчить дocтyп к фaйлy, тaк кaк этoт фaйл зaнят дpyгим пpoцeccoм.".

Как проверить открыт ли он? Понятно, что можно скопировать, стереть и т.д. Но интересует можно ли проверить подругому, какие существуют способы проверки?


 
novice_man ©   (2005-06-07 11:17) [1]

Andy BitOff ©   (07.06.05 10:58)

function FileOpen(const FileName: string; Mode: LongWord): Integer;


File open mode constants:

fmCreate If the file exists, open for write access, otherwise, create a new file. Unlike the other constants, which are declared in the SysUtils unit, this constant is declared in classes.pas.
fmOpenRead Open for read access only.
fmOpenWrite Open for write access only.
fmOpenReadWrite Open for read and write access.
fmShareCompat Compatible with the way FCBs are opened.
fmShareExclusive Read and write access is denied.
fmShareDenyWrite Write access is denied.

fmShareDenyRead Read access is denied.
fmShareDenyNone Allows full access for others.

If the return value is 0 or greater, the function was successful and the value is the file handle of the opened file.

Если файл занят, функция вернет 0


 
novice_man ©   (2005-06-07 11:18) [2]

Попробуйте использовать режим открытия файла fmOpenWrite.


 
Andy BitOff ©   (2005-06-07 11:31) [3]

=)
Если бы все было так просто...


 
Andy BitOff ©   (2005-06-07 11:35) [4]

Файл прекрасно открывается даже с параметром fmShareExclusive


 
NeoVariant ©   (2005-06-07 11:46) [5]

Не знаю, как эта функция будет работать через сетку, но я проверяю на использование файла приложением такой функцией:
function ApplicationUse(fName: string): boolean;
var
 HFileRes: HFILE;
begin
 Result := false;
 if not FileExists(fName) then exit;
 HFileRes := CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE, 0, nil,
   OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
 Result := (HFileRes = INVALID_HANDLE_VALUE);
 if not Result then CloseHandle(HFileRes);
end;

А использовать так:

procedure TForm1.Button1Click(Sender: TObject);
begin
 if ApplicationUse("c:\primer.doc") then
   ShowMessage("файл используется")
 else
   ShowMessage("Файл не используется");
end;


 
Andy BitOff ©   (2005-06-07 11:52) [6]

А я сделал через RenameFile =)

if RenameFile(SomeFile,SomeFile+"~") then begin
 RenameFile(SomeFile+"~",SomeFile);
// файл свободен
end
else begin
// файл занят
end;


 
GreatMaster   (2005-06-07 12:22) [7]

а может ищщо таг:
{$I-}
Reset(f);
if IOResult<>0 then какойтокосяк;
{$I+}



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.024 c
10-1094808578
Kusto
2004-09-10 13:29
2005.06.29
Как вернуть список строк?


4-1115162748
uhhax
2005-05-04 03:25
2005.06.29
Удалить определенную запись в TreeView спомощью TVM_DELETEITEM


14-1117650793
Drow
2005-06-01 22:33
2005.06.29
блок схема


1-1118293185
Wood
2005-06-09 08:59
2005.06.29
Иконка в Application.MessageBox


4-1115175884
Alexandr_jr
2005-05-04 07:04
2005.06.29
CreateFileMapping&amp;MapViewOfFile




   Наверх