0
這裏是一個程序來複制一個目錄到一個新的路徑,但不管程序的目的,我想知道如何簡單退出時按下輸入而不是投入。我想選擇退出而不是輸入輸入
這是我的嘗試使用sys.exit
。在第一次提示時('要複製哪個目錄?'),我只需按回車鍵(不輸入任何數據即可提示),它仍然問我第二個問題(「我可以問哪裏?」)
我想在第一次提示時按回車鍵退出程序。
print "\n" * 5
print "\033[1m" + "Be Careful."
print "\033[0m"
print "\n\tThis program will make changes to your directories.\n\tProceed with caution."
print "\n" * 5
print "\n" * 2
print "Press enter at any prompt to exit."
print "\n" * 5
from sys import exit
import shutil, os
os.chdir('/Users/User/')
butt = raw_input('Which dir you want copy??>> ')
whr = raw_input('And to where may i ask??>> ')
if butt == '' or whr == '':
exit(0)
else:
shutil.copytree(butt, whr)
import os
inputfolder = raw_input('What\'s the path bro???>>>> ')
for foldarName, subfolders, filnames in os.walk(inputfolder):
print('The current folder is ' + foldarName)
for sub in subfolders:
print('SUBFOLDER OF ' + foldarName + ': ' + sub)
for filna in filnames:
print('FILE INSIDE ' + foldarName + ': ' + filna)
print ('')
嗨普約爾。我剛剛嘗試過,並得到完全相同的結果。它不會導致它退出,它只會轉到下一個提示。謝謝 – peer
你不檢查並退出,直到第二個問題後,爲什麼這種行爲會讓你感到驚訝? – jonrsharpe