如何隐藏所有文件类型

2024-04-20 05:27:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在试图隐藏除.exe之外的所有文件。你知道吗

下面隐藏:文件,exe

不隐藏:文件夹

我想要: 隐藏文件夹、文件

不隐藏:.exe

import os, shutil
import ctypes
folder = 'C:\\Users\\TestingAZ1'
for the_file in os.listdir(folder):
    file_path = os.path.join(folder, the_file)
    try:
        if os.path.isfile(file_path):
            ctypes.windll.kernel32.SetFileAttributesW(file_path, 2)
    except Exception as e:
        print(e)

我不能使用-onefile,因为每个exe的大小都很大。你知道吗


Tags: 文件thepathinimport文件夹foros
1条回答
网友
1楼 · 发布于 2024-04-20 05:27:07

也许试着用glob分开,然后藏起来。你知道吗

import glob

files_extensions = ('.exe')

def globby():
    for file in files_extensions:
        _globby = (glob.glob('C:\\Users\\TestingAZ1' + file, recursive=False))
        print(_globby)

globby()

相关问题 更多 >