find what to input in dataPath("") with linux?

edited November 2014 in Programming Questions

So I'm a bit of a newbie in linux, I'm using crunchbang (debian) and I was hoping to test out some of the sketches I made in window...

One of my sektches uses the dataPath() function to find all the jpeg images from a folder. The thing is, I don't know how to find the data path... I know in windows you'd type the drive letter then whatever folders resulting in something like C:/Users/Margsy/processing/mysketch

However, things seem different with linux... I tried this command line in the terminal to find the path to my sketch readlink -f mysketch.pde which gave something like /home/margsy/processing/mysketch/mysketch.pde

So I put dataPath("/home/margsy/processing/mysketch") in my sketch but that really isn't working.

There's not any error message until the sketch tries doing something with the images- at which time it says NullPointerException it didn't find but it's the same problem that happens when I have the data path wrong in Windows, so I'm assuming that's the problem.

Is it because I need to indicate the drive? If so, how do I find it's id? Any hints?

Answers

  • did you try dataPath("") without further content between "" ?

  • edited November 2014

    could you post your windows sketch for us?

  • Answer ✓

    I think you didn't understand what is the point of dataPath(). Giving it a full path has no sense. The point is to prepend the path of the data folder of the current sketch to the given argument:

    dataPath("file.png") should return something like "/path/to/sketchbook/SampleSketch/data/file.png"

  • edited November 2014

    So I'm a bit of a newbie in Gnu/Linux, I'm using CrunchBang (DebIan)...

    Seems like you're more veteran than me who uses simple-minded Ubuntu-based distros! =))

    1 of my sketches uses the dataPath() function...

    Both dataPath() & dataFile() are undocumented functions which point to sketchPath's "/data" subfolder.
    They're not supposed to get some arbitrary folder from the OS's file system! [-X
    For example: String dir = dataPath("") + '/'; yields sketchPath + "/data/".

    If you'd rather prefer some arbitrary folder, you should instantiate a File passing its full path to it: :-B
    https://docs.oracle.com/javase/8/docs/api/java/io/File.html#File-java.lang.String-

  • edited November 2014

    Save and run this sketch as say sketch:-

    PrintWriter pw = createWriter(dataPath("test.txt")); pw.print("done it!"); pw.close();

    Use control 'k' to open sketch folder and there you will have it, a data folder containing 'test.txt'

  • edited December 2014

    Seems like you're more veteran than me who uses simple-minded Ubuntu-based distros!

    Oh I'm not really a veteran, I'm just dumb and decided to start learning Linux with CrunchBang- like 3 weeks ago :') joke definitely on me.

    could you post your windows sketch for us?

    Um this is the context of the code- working from my thumbdrive (I know bad idea but just convenience atm) on Windows...

    This is initial stuff, not in any void...

            // I want to make a sort of "folder searcher" to find all the jpg files
            // we'll have a look in the data folder
            String datapath = "J:/oct22nd";
            java.io.File folder = new java.io.File(dataPath(datapath));
            // let's set a filter (which returns true if file's extension is .jpg)
            java.io.FilenameFilter jpgFilter = new java.io.FilenameFilter() { 
              boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(".jpeg");
              }
            };
            // list the files in the data folder, passing the filter as parameter
            String[] filenames = folder.list(jpgFilter);
    

    Then this is in void draw()

        int rand = int(random(filenames.length));
        img1 = loadImage(datapath + "/" + filenames[rand]);
    

    So what happens is that it selects a random picture from the list and then goes on editing pixels and stuff.

    I had some help writing that so I honestly don't exactly know what everything does in the inital part :$ I wrote a note at the begining of my sketch saying

    // listing files taken from http://wiki.processing.org/index.php?title=Listing_files
     author: antiplastik 
    

    But the link is obselete :'( I was so proud of having documented things properly doe...

    Ummmm but lemme get back to you in a moment because I just realised I wrote .jpeg and all my files are saved as .jpg..........

  • If crunchbang gets too hairy for you, Mint is a very popular distro for a reason. If you follow my previous answer you will find you should only put bare file name in dataPath unless you have sub-directories in the data folder of your sketch (or otherwise don't use it if you want to write out full path).

  • edited December 2014

    Soooooooo I don't know why my sketch works the way it does, where you indicate the full directory in dataPath("") but switching .jpeg to .jpg worked :')

    Still thanks for the help! Now I understand what dataPath is supposed to be for and stuff.

    So um resolved! but not really cause I was, in fact, asking the wrong question :p

  • edited December 2014

    Placing resources inside "/data/" subfolder makes everything tidier and more compatible among OSes!
    Also when the sketch is exported, those resources go along! O:-)

    And as mentioned, Mint 17.1 Rebecca was officially released just 2 days ago:

    But if you still wanna get your hands dirty w/ an expert distro, but w/ æsthetics, Manjaro was just released too:

    Take a general look at Linux distros from this marvelous traditional site:

Sign In or Register to comment.