How to organize the "data" file

Hello,

I was wondering if there was a way to organize the data file into multiple folders. Processing automatically searches the data file, but not other folders inside. Could I add a directory or setting to allow access to folders inside of the data file?

I have many images for different parts of a game. I have images for animated gifs, and images for game textures. I would really like to be able to separate these for ease of access.

Thanks

Answers

  • edited July 2015

    Choose dataPath("") or dataFile(""); passing the name of the folder: :-B

    String gifPath = dataPath("gifs");
    println(gifPath);
    
    File gifFolder = dataFile("gifs");
    println(gifFolder);
    
    exit();
    
  • Thanks for the input, and sorry I am replying so late.

    I tried using the dataPath function, but it seems like it is just tacking the parameter onto the end of the "sketchPath" keyword. It does not include the folder name in the string.

    I tested this by putting a duplicate image in a folder, and the dataPath function gave the same directory. Because of this, the loadImage function does not work.

    I also tried typing out the folder and image name in a string after sketchPath, but this only works for Macs. The Mac directory separators are backslashes were Windows uses forward slashes. The forward slash is an operator, and processing raises a flag unless the forward slash is followed by a key letter such as "n" or "t".

    Is there a way to change the preferences to ignore that forward slash? Is there any other method of obtaining directories?

    Thanks

  • Sorry I fail to pinpoint exactly what you're looking for.
    I've just guessed that you wanted multiple subfolders like "/gifs", "/jpgs", "/sounds", etc. inside subfolder "/data".

  • Yes, that is exactly what I want. The problem that I had was that the "dataPath" function does not include the sub-folder names, so I can not use the directory. And I can not include the sub-folder name myself because Processing wants a command after a "/" in a string.

  • Seems like you didn't even test my example!
    I didn't need to include any "/" nor "\" within the String argument!
    It's simply the name of the subfolder! ~O)

  • Yes, I understand that, but then you are not selecting an image. I did try your example and it didn't work. That is why I tried to use "/".

    In order to load an image, the sub folder directory is not enough. I need the directory to point to an image for the loadImage function will not work.

    I could use the directory to a sub folder if I can somehow integrate it with a namespace, but otherwise it is not enough.

    Test with folder directory

    Test 1 Code

    Test 1 Output

    Test 1 Folder

    Test with image directory

    Test 2 Code

    Test 2 Output

    Test 2 Folder

  • Answer ✓
    String gifPath = dataPath("Random") + '/';
    println(gifPath);
    println(gifPath + "Random Image");
    
    PImage image = loadImage(gifPath + "Random Image.png");
    println(image.width);
    
    exit();
    
  • Oh, I could of just put the forward slash in apostrophes. I forgot about that, thank you.

  • img = loadImage("birds/toucan.png");
    

    just works for me. birds is just a folder in the data folder.

  • edited August 2015

    I think that you are on Mac, because the directory is backwards (What I said in my previous post was wrong, windows uses \, not /)

    One String

    Test Code Test Error

    Parsed String

    Test 2 Code Test 2 Error

  • Ok, I think I found something. After digging around a bit more, I realized that it doesn't matter if you use / or . The problem is that sketchPath and dataPath automatically use \, and you need to use the same character. If you hard code the directory, you can just use /.

  • No. Windows uses either forward or backward slashes, and AFAIK you can mix them.

    If you use backward slashes, you have to double them in strings, because they have a special meaning (eg. used to mark newline \n or carriage return \r, etc.).
    That's to avoid this hassle (and backslashes are harder to type on my keyboard) that I use Unix style paths.

  • edited August 2015

    Windows uses either forward or backward slashes, and AFAIK you can mix them.

    More pedantic: Windows OS uses backward slashes only for its internal file system.
    But Processing itself doesn't care and we can even mix them up in the same String!

Sign In or Register to comment.