Вниз
Скачать: 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.97 c
1-1117610048
Mishenka
2005-06-01 11:14
2005.06.29
Как по имени файла получить его Handle?


8-1109785119
Cerberus
2005-03-02 20:38
2005.06.29
Mp3 и Wav


1-1117894004
Motion
2005-06-04 18:06
2005.06.29
Объявление предела массива


14-1117551392
quickblack
2005-05-31 18:56
2005.06.29
накрылся русский язык в MS Internet Explorer


1-1118047334
john_mag
2005-06-06 12:42
2005.06.29
WorkSheet, WorkBook




   Наверх