我有这段试图重命名目录的 python/tkinter 代码。当 call() 被执行时,它会引发错误。
if os.path.exists(self.destDirectory):
self.now = datetime.datetime.now()
print(self.now)
self.now = str(self.now.strftime("%Y_%m_%d_%H_%M"))
print('rename {0} {1}'.format(self.destDirectory, 'old_' + self.now))
self.cmd1 = ('rename {0} {1}'.format(self.destDirectory, 'old_' + self.now))
self.returnCode1 = call(self.cmd1)
错误:
Exception in Tkinter callback Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "C:\EclipseWorkspaces\csse120\Myproject\src\BoxRestore.py", line 95, in proceed
self.returnCode1 = call(self.cmd1)
File "C:\Python32\lib\subprocess.py", line 467, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python32\lib\subprocess.py", line 741, in __init__
restore_signals, start_new_session)
File "C:\Python32\lib\subprocess.py", line 960, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
但是当我这样做时:
print('rename {0} {1}'.format(self.destDirectory, 'old_' + self.now))
并在 cmd 中执行它,我没有收到任何错误。
另一个命令不会抱怨:
self.cmd2 = ('xcopy {0} {1} /I /E'.format(self.values['sourceButton'], self.values['destinationButton']))
self.returnCode = call(self.cmd2)
你能帮忙吗?