示例#1
0
文件: fs.py 项目: enzbang/e3-core
    def rename(self, filename, replace=False):
        """Move file.

        :param filename: target location
        :type filename: unicode
        :param replace: if True replace the target file if it exists
        :type replace: bool
        :raise: NTException
        """
        target = "\\??\\%s" % os.path.abspath(filename)
        target = target.encode("utf_16_le")
        s = "?PL%ss" % len(target)
        b = create_string_buffer(struct.calcsize(s))
        b.raw = struct.pack(s, replace, 0, len(target), target)
        status = NT.SetInformationFile(
            self.handle,
            pointer(self.io_status),
            b,
            struct.calcsize(s),
            FileInfo.Rename.class_id,
        )
        if status < 0:
            raise NTException(
                status=status,
                message="move of %s to %s failed" % (self.path, filename),
                origin="NTFile.rename",
            )
示例#2
0
    def dispose(self):
        """Remove the file (low level).

        The remove is effective on call to close method
        """
        fd = FileInfo.Disposition(1)
        status = NT.SetInformationFile(self.handle, pointer(self.io_status),
                                       pointer(fd),
                                       sizeof(FileInfo.Disposition),
                                       FileInfo.Disposition.class_id)
        if status < 0:
            raise NTException(status=status,
                              message="cannot dispose",
                              origin="NTFile.dispose")
示例#3
0
    def write_attributes(self):
        """Update file attributes.

        :raise: NTException
        """
        status = NT.SetInformationFile(self.handle, pointer(self.io_status),
                                       pointer(self.basic_info),
                                       sizeof(self.basic_info),
                                       FileInfo.Basic.class_id)
        if status < 0:
            raise NTException(status=status,
                              message='cannot write attributes to %s' %
                              self.path,
                              origin='NTFile.write_attributes')
        self.read_attributes()