打开并锁定一个文件

var
  aHandle     : THandle;
  aFileSize   : Integer;
  aFileName   : String;

procedure TForm1.Button3Click(Sender: TObject);
begin
    aFileName    := ‘C:\101\Java_new.pdf‘;
    aHandle      := CreateFile(PChar(aFileName),GENERIC_READ, 0, nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); // get the handle of the file

    aFileSize   := GetFileSize(aHandle,nil); //get the file size for use in the  lockfile function
    Win32Check(LockFile(aHandle,0,0,aFileSize,0)); //lock the file
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
    Win32Check(UnlockFile(aHandle,0,0,aFileSize,0));//unlock the file
    CloseHandle(aHandle);//Close the handle of the file.
end;

http://stackoverflow.com/questions/1916084/how-do-i-get-the-handle-for-locking-a-file-in-delphi

时间: 2024-07-30 13:39:29

打开并锁定一个文件的相关文章

以追加打开或创建一个文件写入器,来完成简单log

StreamWriter log = new StreamWriter("D:\\" + "ceshi.txt", true);// 如果没有自动创建,并且以追加模式打开    log.WriteLine("time:" + System.DateTime.Now.ToLongTimeString());    log.Close();

PHP文件操作 之读取一个文件(以二进制只读的方式打开)

最近应用了文件的读取,顺便复习一下! //读取一个文件 $f = fopen($filename,'rb'); $f: 表示返回的一个资源句柄 $filename:要打开的文件路径 rb:参数,表示只读且以二进制的形式打开该文件 读取后循环该文件数据,因为读取文件是一行一行的 //如果没有读取到文件结束则循环 while(!feof($f)) { $str = fgets($f);//获取的是每一行的数据 /*对该数据进行的操作代码...*/ } //关闭该资源 fclose($f);

3.5 对一个文件描述符打开一个或多个文件状态标志

lib/setfl.c #include "apue.h" #include <fcntl.h> void set_fl(int fd, int flags) /* flags are file status flags to turn on */ { int val; if ((val = fcntl(fd, F_GETFL, 0)) < 0) err_sys("fcntl F_GETFL error"); val |= flags; /* tu

vim-缓存区中打开另外一个文件的方法

现在有这么一种情况:    我现在在ubuntu用户根目录下--    我根目录下有一个文件夹blogs,这个文件夹下面有两个文件:text1,text2.    我现在从-目录下进行如下操作    vim ~/blogs/text1    然后,我想在已经打开的text1中,使用命令行打开同目录下的text2,那么问题来了,你打算怎么打开呢?    我之前的做法就是,使用命令行,然后用e命令.之后使用../../blogs/text2这样来打开.如果目录层级比较少还好(就像这个例子),那么, 

编写函数,以读模式打开一个文件,将其内容读入到一个string的vector中,将每一行作为一个对立的元素存于vector中

#include<iostream> #include<string> #include<vector> #include<fstream> using namespace std; int main(int argc,char *argv[]) { ifstream input(argv[1]); vector<string> vec; string tmp; while(getline(input,tmp)) { vec.push_back(

linux 打开一个文件现swap文件

转自:http://blog.csdn.net/eckelwei/article/details/17078187 有时候在用vim打开文件时提示类似以下的信息: 发现交换文件 ".exportcert.cpp.swp"所有者: liuchuanliang 日期: Thu Mar 1 17:15:41 2012文件名: ~liuchuanliang/ftsafe/EnterSafe-Shuttle-Linux-111114/i386/sample2/source/ExportCert/

程序4-5 打开一个文件,然后unlink

1 //http://blog.chinaunix.net/uid-24549279-id-71355.html 2 /* 3 ============================================================================ 4 Name : test.c 5 Author : blank 6 Version : 7 Copyright : Your copyright notice 8 Description : 程序4-5 打开一个文件

背水一战 Windows 10 (98) - 关联启动: 使用外部程序打开一个文件, 使用外部程序打开一个 Uri

[源码下载] 作者:webabcd 介绍背水一战 Windows 10 之 关联启动 使用外部程序打开一个文件 使用外部程序打开一个 Uri 示例1.演示如何使用外部程序打开一个文件AssociationLaunching/LaunchFile.xaml <Page x:Class="Windows10.AssociationLaunching.LaunchFile" xmlns="http://schemas.microsoft.com/winfx/2006/xaml

Python3 open() 函数-用于打开一个文件,并返回文件对象,在对文件进行处理过程都需要使用到这个函数,如果该文件无法被打开,会抛出 OSError。

完整的语法格式为: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) 参数说明: file: 必需,文件路径(相对或者绝对路径). mode: 可选,文件打开模式 buffering: 设置缓冲 encoding: 一般使用utf8 errors: 报错级别 newline: 区分换行符 closefd: 传入的file参数类型 opene