“Direktori Pindah Python” Kode Jawaban

File Pindah Python

# To move a file in Python, use one of the following:
import os
import shutil

os.rename("path/to/current/file.foo", "path/to/new/destination/for/file.foo")
shutil.move("path/to/current/file.foo", "path/to/new/destination/for/file.foo")
os.replace("path/to/current/file.foo", "path/to/new/destination/for/file.foo")

# In the first two cases the directory in which the new file
# is being created must already exist.
SkelliBoi

Ubah Direktori di Python OS

import os

path = "C:\Users\Your\Directory"

os.chdir(path)
Joyous Jellyfish

Ubah direktori dalam skrip python

os.chdir(os.path.dirname(__file__))
Splendid Sandpiper

Direktori Pindah Python

import shutil

original = r'C:\games' # original folder / file path 
target = r'D:\homework' # where to move it 

shutil.move(original, target)
cabiste

Jawaban yang mirip dengan “Direktori Pindah Python”

Pertanyaan yang mirip dengan “Direktori Pindah Python”

Lebih banyak jawaban terkait untuk “Direktori Pindah Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya