Вниз
Скачать: 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
1-1118208998
MarS
2005-06-08 09:36
2005.06.29
Прокрутить Image


3-1115969620
pc-hunter
2005-05-13 11:33
2005.06.29
Печать базы даных


6-1112005371
DICE
2005-03-28 14:22
2005.06.29
Подключение к онлайновой игре


14-1117912350
Dezmond
2005-06-04 23:12
2005.06.29
MS C# vs Borand C#


3-1116562845
Alex_d
2005-05-20 08:20
2005.06.29
Добавление поля в уже существующую таблицу




   Наверх