Anasayfa / python / Python Windows SetFileAttributesW folder subfolder files

Python Windows SetFileAttributesW folder subfolder files

import os
import ctypes

FILE_ATTRIBUTE_READONLY = 0x01
FILE_ATTRIBUTE_HIDDEN = 0x02
FILE_ATTRIBUTE_SYSTEM = 0x04
FILE_ATTRIBUTE_DIRECTORY = 0x10
FILE_ATTRIBUTE_ARCHIVE = 0x20
FILE_ATTRIBUTE_NORMAL = 0x80
FILE_ATTRIBUTE_TEMPORARY = 0x0100


def set_attribute_single(path_or_file, attr_name):
    ret = ctypes.windll.kernel32.SetFileAttributesW(path_or_file,
                                                    attr_name)
    if ret:
        print(path_or_file,' ok')
    else:  # return code of zero indicates failure -- raise a Windows error
        raise ctypes.WinError()


def set_attribute_folder_and_file_all(path_or_file, attr_name):
    set_attribute_single(path_or_file, attr_name)
    for path, subdirs, files in os.walk(path_or_file):
        for name in files:
            set_attribute_single(os.path.join(path, name), attr_name)
    return True


set_attribute_folder_and_file_all(r'C:\Users\MasterYoda\Desktop\PySample\', FILE_ATTRIBUTE_NORMAL)

 

Hakkında ibrahim

İlgili Makaleler

python DownloadProgressBar

import urllib import urllib.request from tqdm import tqdm class DownloadProgressBar(tqdm): def update_to(self, b=1, bsize=1, tsize=None): …

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir