当我使用%H:%M:%S时,我会得到下面给出的错误。如果我把它和圆点一起使用,一切都很好。有人能解释一下原因吗?以及如何使用冒号?
这是代码:
import os, time, zipfile
source = ["C:\Users\Daniel\Documents\Projects", "C:\Users\Daniel\Pictures\pics"]
target_dir = 'D:\Backup'
today = target_dir + os.sep + time.strftime('%Y.%m.%d')
comment = input('Enter a comment: ')
com = comment.replace(' ', '_') + '.zip'
now = time.strftime('%Y.%m.%d. %H:%M:%S')
if not os.path.exists(today):
os.mkdir(today)
print('Folder made successfully')
if len(comment) == 0:
target = today + os.sep + now + '.zip'
else:
target = today + os.sep + now + '_' + com
z = zipfile.ZipFile(target, 'w' )
def zip(c):
for a in c:
for folder, subfolder, files in os.walk(a):
for file in files:
z.write(os.path.join(folder, file))
zip(source)
z.close()
这是错误的回溯:
Traceback (most recent call last):
File "c:UsersDanielDocumentsProgrammingbackupscript.py", line 38, in <module>
z = zipfile.ZipFile(target, 'w' )
File "C:UsersDanielAppDataLocalProgramsPythonPython310libzipfile.py", line 1249, in __init__
self.fp = io.open(file, filemode)
OSError: [Errno 22] Invalid argument: 'D:\Backup\2022.11.04\2022.11.04. 16:59:39_wa_w.zip'
:
在Windows上的使用受到限制。此外,以下是保留字符:
<
(小于(>
(大于("
(双引号(/
(正斜杠((反斜杠(
|
(立筋或立管(?
(问号(*
(星号(
您可以在这里阅读更多