PermissionError:[Errno 13]权限被拒绝:'desktop.ini'

时间:2018-03-01 10:12:31

标签: python python-3.x

import os, subprocess, configparser

# Search for folder!
# First locate the directory
root_dir = input("Enter the root directory you wanna enter:")
try:
    os.chdir(root_dir)
except FileNotFoundError:
    print("ERROR:Directory not found")
    exit(505)
# second locate the folder now!
folder_name = input("Enter the name of folder you wanna hide:")

# Hiding part starts now!
# check the entered information
# Start by checking if the folder is present in the directory
check_dir = os.listdir(root_dir)
print(check_dir)
if folder_name in check_dir:
    # If the folder is present lets hide it!

    # step 1: Give a hidden name(No-Break space) by pressing alt + 0160
    folder = ' '
    os.rename(folder_name, folder)

    # step 2: Enter the properties of this folder
    # first change the folder to read only using cmd
    subprocess.call('cd' + " " + root_dir, shell=True)
    cmd_command = "attrib +s" + " " + folder
    returned = subprocess.call(cmd_command, shell=True)
    print("Shell returned", returned)
    # second change the folder icon with desktop.ini and configParser
    config = configparser.RawConfigParser()
    config['.ShellClassInfo'] = {
        'ConfirmFileOp': '0',
        'NoSharing': '1',
        'IconFile': 'Folder.ico',
        'IconIndex': '0',
        'InfoTip': 'This is folder man'
    }
    with open("desktop.ini", "wt") as configFile:
        config.write(configFile)
else:
    print("ERROR: folder not present!!!")

# Check At the end for success
print(os.listdir(root_dir))

我目前正在尝试创建隐藏文件夹的程序,但出于某种原因,我收到此错误:

  

open(“desktop.ini”,“wt”)as configFile:   PermissionError:[Errno 13]权限被拒绝:'desktop.ini'

帮助!!!

0 个答案:

没有答案