0
import os, shutil
directory = 'C:\\Users\\MinJun\\Documents\\Python exercise solutions'
def move_files(_dir):
for file in os.listdir(_dir): #check every file in directory
if os.path.isdir(file): #if it is a folder, skip
continue
if file.endswith('.py'): #if file ends with .py, skip
continue
else: #move file to newfolder, (it will automatically create one)
shutil.move(file, directory.join('\\newfolder'))
move_files(directory)
こんにちは、私は存在しないフォルダにフォルダやファイルの.pyでないファイルを移動しようとしている(であろうがいますshutil.moveで作成されます)。
FileNotFoundError:[Errno 2]そのようなファイルまたはディレクトリはありません: 'graphics'shutilとOSでの作業:[errnoを2]いいえそのようなファイルまたはディレクトリ「フォルダ」
myフォルダ 'graphics'がディレクトリ内の最初の項目です。 https://docs.python.org/3.5/library/stdtypes.html#str.join
をあなたはそれをもたらし、そしてこのパスは確かに存在しないためという何を見ることができますprint(directory.join('\\newfolder'))
場合: