Quantcast
Channel: okmem.com - Latest entries
Viewing all articles
Browse latest Browse all 15

python 目录处理以及拷贝

$
0
0

python os.path path

 

 

import shutil
import os"""
python handle windows path
cpoy tree"""

print "UNC--------------------"
#Define UNC path
src_1 = r'\\xxx\yyy\zzz'
src_2 = "\\\\xxx\\yyy\\zzz"
#Get UNC absolute path
print "absolute"
print os.path.abspath(src_1)
print os.path.abspath(src_2)
#get UNC absolute dir path
print "absolute dir"
print os.path.dirname(src_1)
print os.path.dirname(src_1)
#ADD \ and anything at the end of the path will get the currect path,even the ending is not exist
print 'add anything to the end'
src_3 = r'\\xxx\yyy\zzz\?'
src_4 = "\\\\xxx\\yyy\\zzz\*"
print os.path.dirname(src_3)
print os.path.dirname(src_4)

print "WINDOWS----------------------"
#Define windows path
src_1 = r'c:\\xxx\yyy\zzz'
src_2 = "c:\\xxx\\yyy\\zzz"
#Get UNC absolute path
print "absolute"
print os.path.abspath(src_1)
print os.path.abspath(src_2)
#get UNC absolute dir path
print "absolute dir"
print os.path.dirname(src_1)
print os.path.dirname(src_1)
#ADD \ and anything at the end of the path will get the currect path,even the ending is not exist
print 'add anything to the end'
src_3 = r'c:\\xxx\yyy\zzz\?'
src_4 = "c:\\xxx\\yyy\\zzz\*"
print os.path.dirname(src_3)
print os.path.dirname(src_4)


#define copy to
print "dst path------------------------------"
print os.path.join(os.path.abspath(src_1),"tmp")


#make sure copy to no exist
shutil.copytree(os.path.dirname(src_1),os.path.join(os.path.dirname(dst_1),'tmp'))

 


Viewing all articles
Browse latest Browse all 15

Trending Articles