Copy certain files from one folder to another using python

纵饮孤独 提交于 2019-12-05 06:01:29

Given the name of the file columns['label'] you can use the following to move a file

srcpath = os.path.join(src, columns['label'])
dstpath = os.path.join(dst, columns['label'])
shutil.copyfile(srcpath, dstpath)

Here is the script I used to solve my problem:

import os
import arcpy
import os.path
import shutil
featureclass = "C:\\work_Data\\Export_Output.shp"
src = "C:\\Data\\UC_Training_Areas"
dst = "C:\\Data\\Script"

rows = arcpy.SearchCursor(featureclass)
row = rows.next()
while row:
     print row.Label
     shutil.move(os.path.join(src,str(row.Label)),dst)
     row = rows.next()

Think of it this ways way source and destination assuming you want to copy file from your picture folder to your image folder located somewhere in your machine destination
X is your machine name Z is the file name``

import os;
import shutil;
import glob;

source="C:/Users/X/Pictures/test/Z.jpg"
dest="C:/Users/Public/Image"

    if os.path.exists(dest):
    print("this folder exit in this dir")
else:
    dir = os.mkdir(dest)

for file in glob._iglob(os.path.join(source),""):
    shutil.copy(file,dest)
    print("done")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!