に変更a.txt
したいb.kml
。
550672 次
16 に答える
862
使用os.rename
:
import os
os.rename('a.txt', 'b.kml')
于 2010-03-22T10:00:52.207 に答える
121
ファイルがディレクトリ内にある可能性があります。その場合、パスを指定します。
import os
old_file = os.path.join("directory", "a.txt")
new_file = os.path.join("directory", "b.kml")
os.rename(old_file, new_file)
于 2015-10-15T09:15:07.007 に答える
64
import shutil
shutil.move('a.txt', 'b.kml')
これは、ファイルの名前変更または移動に機能します。
于 2010-03-22T10:00:41.007 に答える
20
os.rename(old, new)
これは Python ドキュメントにあります: http://docs.python.org/library/os.html
于 2010-03-22T10:00:55.463 に答える
6
Python バージョン 3.3 以降では、宛先ファイルが既に存在する場合は、os.replace
代わりにos.rename
soを使用することが一般的に推奨されます。FileExistsError
assert os.path.isfile('old.txt')
assert os.path.isfile('new.txt')
os.rename('old.txt', 'new.txt')
# Raises FileExistsError
os.replace('old.txt', 'new.txt')
# Does not raise exception
assert not os.path.isfile('old.txt')
assert os.path.isfile('new.txt')
ドキュメントを参照してください。
于 2021-08-10T20:31:40.113 に答える
-1
os.chdir(r"D:\Folder1\Folder2")
os.rename(src,dst)
#src と dst は Folder2 内にある必要があります
于 2020-12-11T18:46:15.063 に答える
-4
os.system を使用して端末を呼び出し、タスクを実行できます。
os.system('mv oldfile newfile')
于 2016-01-11T05:02:24.767 に答える