Hello Ventuzians!
THE FORUMS ARE CLOSED!

Please join our discord server HERE!! << click me :D

We are shutting our Ventuz Forum, but don't worry, it will all be archived for you to search in if you have a query. From now on, please add all your comments, questions or observations into our Discord Server

Thanks for the great time - see you on discord!!
Dee, Karol, Daniel and the whoooole Product and Support team!

Check if DIRECTORY exists?

Q and A about functionality and how to solve a special task for your application.

Moderator: Support

Post Reply
dondi
Posts: 19
Joined: 08 Mar 2013, 22:11

Check if DIRECTORY exists?

Post by dondi » 03 Nov 2014, 21:35

I am new to Ventuz and working on a personal project to help me learn. I am doing the obligatory Music (Now Playing) Visualizer. I have tons of art that I have procured over some time that I can use for this project. Currently, I am working with ARTIST 'fanart' where I am trying to load-in 3 random pieces of fanart of the currently-playing ARTIST into a background scene from a specific directory. In my project\images folder I have made a copy of my MUSIC ART folder that contains subdirectories categorized by ARTIST NAME. These subfolders contain a thumbnail of the ARTIST (folder.jpg), BANNER ART (banner.jpg), LOGO ART (logo.png), and CDArt (cdart.png - images of the album disc art), etc.

Most of the time, but not all of the time (depending upon how obscure the artist is), there is another subfolder named EXTRAFANART that contains the images that I am currently trying to work with. I am able to load-in these images, as well as check for their existence AFTER I load them into an array. I'd like a more elegant solution where I can check to see if the EXTRAFANART folder exists BEFORE I load it into an array. Ventuz throws errors otherwise.

More specifically, I am using the NOW PLAYING ARTIST as a String variable and creating the following (A+B+C) expression:
A = .\Images\Music Library Art\
B = @ARTIST (Artist name loaded dynamically from currently-playing song)
C = \extrafanart\ (folder that may, or may not exist that contains the background art)

RESULT = .\Images\Music Library Art\[@ARTIST]\extrafanart\

It would be at this point where I'd like to check the URI for the existence of the EXTRAFANART folder, but I have not yet found a way to do that using the URL node directly- or indirectly-connected to this expression. The way I am able to do this checking process is to take the resulting expression path and plug it into a DIRECTORY node that reads *.jpg into an array and creates a resulting RESULTARRAY, COUNT and URI. I am then able to use the URL node to check if there exists any files (more specifically, it looks like it checks if there exists a .JPG as the first item) and throws an EXISTS flag as the result. It'd be easier if the fanart filenames were predictable, but these came from a database and the .jpg filenames are arbitrary. So, basically at this point, I am loading-in null items into the array if the folder is not there and I'd like to find a way to avoid this, if possible.

chriss0212
Posts: 666
Joined: 18 Jan 2012, 20:56
Location: wuppertal
Contact:

Re: Check if DIRECTORY exists?

Post by chriss0212 » 04 Nov 2014, 10:13

hi dondi

to check if a folder exist you need a c# script!

or, you just check the numbers of files in a folder...what is of course 0 if there is no folder ;)

greetz

christian

User avatar
Götz_B
Posts: 180
Joined: 21 May 2013, 13:01

Re: Check if DIRECTORY exists?

Post by Götz_B » 04 Nov 2014, 10:49

Hi Dondi,

you can use .NET functions in expressions. The Directory-Class is helpful in your case. It has an exists method. There are other useful classes in the System.IO Namespace when you work on filenames - for example the Path-Class to get fileextensions etc.
To use these in an expression you have to use the full name like System.IO.Directory.Exists().

Of course a script also works, but an expression is a bit less overhead.

Regards,

Götz

Christian Krix Schmidt
Posts: 290
Joined: 18 Jan 2012, 11:36
Location: Dubai, United Arab Emirates
Contact:

Re: Check if DIRECTORY exists?

Post by Christian Krix Schmidt » 04 Nov 2014, 11:42

Didn't know that one. Excellent. Thanks.

chriss0212
Posts: 666
Joined: 18 Jan 2012, 20:56
Location: wuppertal
Contact:

Re: Check if DIRECTORY exists?

Post by chriss0212 » 04 Nov 2014, 20:20

hey götz,

thx for info ;)

greetz

christian

dondi
Posts: 19
Joined: 08 Mar 2013, 22:11

Re: Check if DIRECTORY exists?

Post by dondi » 04 Nov 2014, 20:29

Thanks for the feedback all.

I am far from being an avid coder, but I can hack around a bit, so this is a bit of a challenge stepping-into this new territory.

Christian, regarding your second suggestion checking for 0 files; I think (if I am not mistaken) that I can get a file count only after I load/read the files using the DIRECTORY node, which gives me a file count as well as automatically creating a ResultArray of URIs, which is where Ventuz is not happy trying to load nulls into the array in the first place when the EXTRAFANART directory is not present.

That being said, SUCCESS!!!

I was able to come up with a more-elegant (error-free) solution/design based on Gotz's suggestion:

• I am taking the result of my previous String Expression that points to the path of the extrafanart folder of the currently-playing artist
• My new .NET expression has the following:
A = string path result of previous expression (.\Images\Music Library\[@ARTIST]\extrafanart\
C = 1
D = 0
Expression = System.IO.Directory.Exists(A) ? C : D

Result = Boolean that I am using as the index in a Multi-Switch Node with four output cases.
• When true, I pass the URI to a Directory Node as one of my Multi-Switch outputs, which then loads the Array Indexer as well as fires-off a random Mover to select an arbitrary file in the array index and passes the next 3 images back to the other 3 exposed case outputs of the Multi-Switcher.
• When false (no extrafanart folder exists), I pass 3 URIs to default .JPGs onto the 3 exposed Multi-Switcher outputs, bypassing loading the array altogether.

Thanks again for all the help as I hack-away in Ventuz!
-- Dondi

Post Reply