Вниз
Скачать: 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.04 c
4-1114577998
bobah
2005-04-27 08:59
2005.06.29
Невидимый курсор мыши


1-1117797070
Mishenka
2005-06-03 15:11
2005.06.29
Как посчитать контрольную сумму файла?


6-1110568217
Bailey
2005-03-11 22:10
2005.06.29
pereslat record cheres UDP indy 10


6-1112087491
Sapsi
2005-03-29 13:11
2005.06.29
найти все компьютеры в сети


3-1116571267
~Alex
2005-05-20 10:41
2005.06.29
Блокировки таблиц




   Наверх