【问题标题】:how to hide all excluding file type如何隐藏所有不包括文件类型
【发布时间】:2018-05-30 06:43:06
【问题描述】:

我正在尝试隐藏除.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 文件都很大。

【问题讨论】:

    标签: python file operating-system hide glob


    【解决方案1】:

    也许可以尝试使用 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()
    

    【讨论】:

    • 你能举例说明我的文件夹是:C:\\Users\\TestingAZ1。 Atm 我没有看到任何变化。
    • 好的,所以当我运行它时,目录中没有任何变化。
    猜你喜欢
    • 2011-10-12
    • 2021-11-03
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 2018-05-23
    • 2014-12-13
    • 1970-01-01
    相关资源
    最近更新 更多