Python: get last folder from path

7 12 2012

20121207

ต้องการใช้ชื่อโฟล์ดเดอร์สุดท้าย ไปใช้งานสามารถทำได้ดังนี้

code:

import os
mypath = ‘G:\Python\Sample\lastFolder’
print os.path.basename(os.path.normpath(mypath)

the result is “lastFolder”


Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: