请教这样用Delphi 把一个只读文件佳设置为可写? 怎么样又把文件夹设置为不可写.

解决方案 »

  1.   

    两个函数。FileGetAttr 获取指定文件的属性
    FileSetAttr 设置指定文件的属性
      

  2.   

    BOOL SetFileAttributes(
        LPCTSTR lpFileName, // address of filename 
        DWORD dwFileAttributes  // address of attributes to set 
       );FILE_ATTRIBUTE_ARCHIVE The file is an archive file. Applications use this value to  files for backup or removal.
    FILE_ATTRIBUTE_HIDDEN The file is hidden. It is not included in an ordinary directory listing.
    FILE_ATTRIBUTE_NORMAL The file has no other attributes set. This value is valid only if used alone.
    FILE_ATTRIBUTE_OFFLINE The data of the file is not immediately available. Indicates that the file data has been physically moved to offline storage.
    FILE_ATTRIBUTE_READONLY The file is read-only. Applications can read the file but cannot write to it or delete it.
    FILE_ATTRIBUTE_SYSTEM The file is part of the operating system or is used exclusively by it.
    FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.如:SetFileAttributes(PChar(C:\1.txt), FILE_ATTRIBUTE_NORMAL)
      

  3.   

    做个批处理在delphi里启动这个批处理文件,就可以了。
    比如
    attrib -r  c:\新建文件夹\test.txt
    要实现改变文件夹只要把文件地址改为文件夹地址就行
    attrib -r  c:\新建文件夹把代码写入txt文档后缀改为.bat就可运行
      

  4.   

    文件夹改为不可写不是-r是+r
    attrib   +r     c:\新建文件夹 
    写错了,不好意思啊