내가 생각하고 있지만, 파이썬 꽂으십시오 'os' 인터페이스입니다 파일을 이동할 수 있는 방법을 찾을 수 없습니다. 어떻게 할까요? '에서' $ mv 에 있다.
>>> source_files = '/PATH/TO/FOLDER/*'
>>> destination_folder = 'PATH/TO/FOLDER'
>>> # equivalent of $ mv source_files destination_folder
['오드리나미 ()'] [1], ['슈틸드모브 ()'] [2] 또는 ['오스트리플레이스 ()'] [3]
같은 문법을 사용하는 모든
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")
포함시키십시오 합니다 모두 및대상 인수만 소스 파일 이름 ('피레스포'). 물론 변경할 경우, 해당 파일은 renamed 이동했습니다. 또한 처음 두 가지 사례 디렉터리입니다 만들어지는 새 파일이 있어야 합니다. Windows 에서 그 이름을 가진 파일이 존재하지 않아야 합니다 호스트였든 idfsysobject. 오스트리플레이스 () '가 아니라' 높아질 것이라고 할 수 있는 파일을 자동으로 복귀시킴 에셋은.
그동안 명시된 것처럼 다른 대답이 ',' 댓글 '대부분의 경우' 오드리나미 슈틸드모브 호출할 수 있습니다. 그러나, 그 대신 다른 디스크 대상 켜있을 소스보다 복사한 다음 소스 파일 삭제.
[1]: http://docs.python.org/library/os.html # 오드리나미 [2]: http://docs.python.org/library/shutil.html # 슈틸드모브 [3]: https://docs.python.org/library/os.html # 오스트리플레이스
비록 '오드리나미 ()' 와 '슈틸드모브 ()' 는 모두 유닉스 파일 이름 변경, 가장 가까운 슈틸드모브 () 는 'mv 명령을 명령'. 다른 점은 오드리나미 () ',' t # 39 doesn& 경우 다른 디스크에 동시에 작동합니까 소스와 대상이 슈틸드모브 () ',' t care doesn& # 39 어떤 디스크 파일 오른길로.
또는 슈틸드모브 임포트하십시오 모듈에서는 중 하나를 오드리나미 합니다.
우리는 폴더란 dell. / opt 라는 파일을 소스 하나로 와섬.t스트리 불렀으매 / 멋져
in /opt/awesome
○ → ls
source
○ → ls source
awesome.txt
python
>>> source = '/opt/awesome/source'
>>> destination = '/opt/awesome/destination'
>>> import os
>>> os.rename(source, destination)
>>> os.listdir('/opt/awesome')
['destination']
실제로 칼리오피 우린 오스트리스타디르 확인하기 위해 폴더 이름이 바뀌었다.
>>> import shutil
>>> shutil.move(destination, source)
>>> os.listdir('/opt/awesome/source')
['awesome.txt']
이번엔 제가 점검됩니다 소스 파일 폴더 안에 있는 내가 만든 와섬.t스트 확인할 수 있습니다. 그리고 그 속에는:)
이제 우리는 다른 폴더와 파일 소스에서 대상 및 다시.
이게 I& # 39 를 사용하여, m 이 순간.
import os, shutil
path = "/volume1/Users/Transfer/"
moveto = "/volume1/Users/Drive_Transfer/"
files = os.listdir(path)
files.sort()
for f in files:
src = path+f
dst = moveto+f
shutil.move(src,dst)
이제 전기능. ᄋ "이번 도움이 됩니다.
import os, shutil, pathlib, fnmatch
def move_dir(src: str, dst: str, pattern: str = '*'):
if not os.path.isdir(dst):
pathlib.Path(dst).mkdir(parents=True, exist_ok=True)
for f in fnmatch.filter(os.listdir(src), pattern):
shutil.move(os.path.join(src, f), os.path.join(dst, f))
설명됨 여기서요 오토메이티드 따라 또 다른 옵션을 사용하여 하위 ','.
이 같은 일이.
subprocess.call("mv %s %s" % (source_files, destination_folder), shell=True)
Is it 시스템 종속적입니다 아마?
이 솔루션을 통해 '쉘로 않는 "사용' mv '.
import subprocess
source = 'pathToCurrent/file.foo'
destination = 'pathToNew/file.foo'
p = subprocess.Popen(['mv', source, destination], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
res = p.communicate()[0].decode('utf-8').strip()
if p.returncode:
print 'ERROR: ' + res
import os,shutil
current_path = "" ## source path
new_path = "" ## destination path
os.chdir(current_path)
for files in os.listdir():
os.rename(files, new_path+'{}'.format(f))
shutil.move(files, new_path+'{}'.format(f)) ## to move files from
서로 다른 디스크 emailxtender. C: - >. D: