Я пытаюсь написать программу, чтобы получить все мои .cpp-файлы из папки документов/VisualStudio2008, но мне трудно скопировать их на рабочий стол. Я хочу, чтобы он перемещал все .cpp из указанной папки на рабочий стол. У меня стандартная схема именования, и я сделал все, о чем я могу думать. Любая помощь приветствуется. Код ниже, если вам нужна дополнительная информация, просто спросите.Проблемы с копированием файлов в python
import shutil, os
src = ""
dest = ""
chapter = 0
type = ["StepByStep", "Project", "Activity"]
currentType = 0
chapter = int (input("What chapter files would you like to get?\n>> "))
destFolder = input("What do you want the folder name to be?\n>> ")
dest = "C:/Users/17haydent/desktop/"
src = "C:/Users/17haydent/Documents/Visual Studio 2008/Projects/"
#srcEnd = name/name/name.cpp
def upType():
global currentType
if currentType == 0:
currentType = 1
elif currentType == 1:
currentType = 2
dest += destFolder
for a in range(1, 3):
for b in range(1, 20):
newSrc = src + type[currentType] + str(chapter) + '_' + str(b) + '/' + type[currentType] + str(chapter) + '_' + str(b) + '/' + type[currentType] + str(chapter) + '_' + str(b) + ".cpp"
newDest = dest + '/' + type[currentType] + str(chapter) + '_' + str(b) + ".cpp"
try:
assert not os.path.isabs(newSrc)
dstdir = os.path.join(newDest, os.path.dirname(newSrc))
os.makedirs(dstdir) # create all directories, raise an error if it already exists
shutil.copyfile(newSrc, dstdir)
except:
print("Error copying file", newSrc, "to", newDest)
upType()
Вы представили свой сценарий и дали код. Но в чем проблема? Что работает не так, как ожидалось? – Lovato