사용자 정의 디렉토리에서 파일 목록을 가져 오는 데 약간의 문제가 있습니다. 다음 코드는 정상적으로 작동합니다.Python - 사용자 입력으로 파일 디렉토리 받기
inputdirectory = r'C:/test/files'
inputfileextensions = 'txt'
files = glob.glob(inputdirectory+"*."+inputfileextensions)
하지만 사용자가 위치를 입력 할 수있게하려고합니다. 다음 코드를 시도했습니다 :
inputdirectory = input("Please type in the full path of the folder containing your files: ")
inputfileextensions = input("Please type in the file extension of your files: ")
files = glob.glob(inputdirectory+"*."+inputfileextensions)
그러나 작동하지 않습니다. 오류 메시지는 나타나지 않지만 파일은 비어있는 것으로 반환됩니다. 따옴표가있는 디렉토리에 정방향 및 역방향 슬래시를 입력하려고 시도했지만 작동시키지 못했습니다. 또한 'r'을 사용하여 원시 문자열로 입력을 변환하려고 시도했지만 어쩌면 구문에 의해 잘못되었습니다. 어떤 아이디어?
인쇄 :'inputdirectory + "*."+ inputfileextensions' –