无法在Windows资源管理器中查看文件夹,无法重命名

时间:2016-03-24 18:29:55

标签: python scripting automation windows-10

我是编程,python和StakeOverflow的新手(我在大学里有一门编程课程,在高中时有一门编程课程)。我制作了这个脚本来清理我的下载文件夹但是我遇到了一些问题。我创建的文件夹在Windows资源管理器中不可见,我似乎无法重命名我创建的文件夹。如果这有任何不同,我正在运行Windows 10。

import os
import time
import shutil


# Create a folder to store the downloads in
def makefolder():
    os.chdir(os.chdir('C:\\')
    os.makedirs('C:\Users\keega\Documents\A')

# Moves the files
def movefiles():
    os.chdir('C:\Users\keega\Documents\Downloads')
    shutil.copytree('C:\Users\keega\Documents\Downloads','C:\Users\keega\Documents\A')


# Rename the folder just created
def renamefolder():
    os.chdir('C:\Users\keega\Documents')
    nameoffolder= 'Downloads' + str((time.strftime("%d/%m/%Y")))
    os.rename('A',nameoffolder)
    Return

#delete the old files
def deletedownloads():
    os.chdir('C:\Users\keega\Downloads')
    shutil.rmtree('C:\Users\keega\Downloads')


makefolder()
movefiles()
renamefolder()
deletedownloads()

1 个答案:

答案 0 :(得分:0)

将大写的C:更改为c:\,并删除文件夹A,因为它将再次创建,否则将运行错误。

import os
import time
import shutil


# Create a folder to store the downloads in
def makefolder():
    os.mkdir('c:\\Users\\keega\\Documents\\A')

# Moves the files
def movefiles():
    os.chdir('c:\\Users\\keega\\Documents\\Downloads')
    shutil.copytree('c:\\Users\\keega\\Documents\\Downloads','c:\\Users\\keega\\Documents\\A')


# Rename the folder just created
def renamefolder():
    os.chdir('c:\\Users\\keega\\Documents')
    nameoffolder= 'Downloads' + str((time.strftime("%d/%m/%Y")))
    os.rename('A',nameoffolder)
    Return

#delete the old files
def deletedownloads():
    os.chdir('c:\\Users\\keega\\Downloads')
    shutil.rmtree('c:\\Users\\keega\\Downloads')


makefolder()
movefiles()
renamefolder()
deletedownloads()