Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

get basename from path

Still a little green? Ask your beginner's questions here

get basename from path

Postby madmatt » Fri Oct 12, 2018 8:51 am

Hi all,
I' m getting mad trying to figure out how can i get the filename of a file from a specific path.
I can't use folder dat, i have a specific path of a file and i need to get the basename.
Something like the os module can do in python.
There should be some implementation of that since the folder dat can do that.
But i cant figure out how can i do that with my specific code.
madmatt
 
Posts: 3
Joined: Fri Dec 02, 2016 7:28 pm

Re: get basename from path

Postby Qvoloid » Sat Oct 13, 2018 2:44 am

Hey there,

Can you elaborate a little bit more? You say:

I can't use folder dat, i have a specific path of a file and i need to get the basename.


Why can't you use folder? You can select in the name format the option "No extension" to have the basename of a file on the folder you are pointing to.

You also say:
Something like the os module can do in python.


Well, then why not using the os package? Is trivial to point to a path and getting its basename:

Code: Select all
import os

# Get basename of a file
os.path.basename(path)


Best,
Darien
__________
Darien Brito | AV artist - Multimedia Programmer
Qvoloid
 
Posts: 58
Joined: Wed Jun 25, 2014 6:29 pm
Location: Netherlands, Den Haag

Re: get basename from path

Postby rob » Mon Oct 15, 2018 12:05 pm

And as a small tip, if you want to include that all as a single expression in a parameter:

Code: Select all
__import__('os').path.basename(path)
User avatar
rob
Staff
 
Posts: 1557
Joined: Tue Nov 13, 2007 1:14 am

Re: get basename from path

Postby nettoyeur » Tue Oct 16, 2018 4:16 pm

Nice one Rob, didn't know that!
Idzard Kwadijk | freelance TouchDesigner consultant | LinkedIn
Checkout ChopChopChop.org - the TouchDesigner marketplace!
nettoyeur
 
Posts: 993
Joined: Mon Oct 15, 2012 12:00 pm
Location: Amsterdam, The Netherlands

Re: get basename from path

Postby rob » Fri Oct 19, 2018 11:02 am

Should add __import__() is a built-in Python function.

Inside TouchDesigner however, you can use the shorter:

Code: Select all
mod.os.path.basename(path)


mod (or 'Module On Demand') searches DAT operators, then if not found, external python modules:

https://docs.derivative.ca/MOD_Class
User avatar
rob
Staff
 
Posts: 1557
Joined: Tue Nov 13, 2007 1:14 am

Re: get basename from path

Postby Qvoloid » Sat Oct 20, 2018 3:22 am

Fantastic! Didn't know that either. Thanks Rob!
__________
Darien Brito | AV artist - Multimedia Programmer
Qvoloid
 
Posts: 58
Joined: Wed Jun 25, 2014 6:29 pm
Location: Netherlands, Den Haag


Return to Beginners

Who is online

Users browsing this forum: AngryPrimate69 and 13 guests