Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2005.06.29;
Скачать: [xml.tar.bz2];

Вниз

Ошибка: "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 вся ветка

Форум: "Основная";
Текущий архив: 2005.06.29;
Скачать: [xml.tar.bz2];

Наверх




Память: 0.45 MB
Время: 0.047 c
14-1117707479
12DFBDDh
2005-06-02 14:17
2005.06.29
Он лайн библиотека "Архивариуса"


3-1116317238
Lord Zmiy
2005-05-17 12:07
2005.06.29
dbf - кодировка


1-1117618938
Стас
2005-06-01 13:42
2005.06.29
Что за ошибка


1-1117782191
BigBan
2005-06-03 11:03
2005.06.29
Операции со строками


14-1117642269
Delphinium
2005-06-01 20:11
2005.06.29
Visual C++





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский