send file path processing to pure data with OSC

edited November 2013 in Library Questions

hi all

i try to send the ''absolutePath'' from selectFile() to variable ''pdFilePath'' and send this variable to puredata with osc

if i make a println(pdFilePath); i have this result:
C:\Users\Danny\Documents\Mallette magique\Sample Documents\pd musictable\son\solid hl.wav

then processing send osc variable ''pdFilePath'' and this now my problem

in pure data i receive my variable wich give this:
C:\\\\Users\\\\Danny\\\\Documents\\\\Mallette magique\\\\Sample Documents\\\\pd musictable\\\\son\\\\solid hl.wav

now this is what pure data do with an [openpanel]:
C:/Users/Danny/Documents/Mallette magique/Sample Documents/pd musictable/son/solid hl.wav

why pure data gives me 4 slash between the file?

i need processing send file path to pure data to play a music file

somebody have an idea with this strange problem ?

Wholesale its pure data patch

[inlet processing]
|
[unpack s]
!
[symbol  \
|
[print]

this is the selectinput() processing code:

String pdFilePath = "file.wav";

void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
    pdFilePath = selection.getAbsolutePath();
  }
}

thx a+

Answers

  • Sometime, Java converts backslashes (specific to the Windows system) to regular slashes (more universal, also working on Windows, BTW).

    Such path should still work to open files, etc. Is it a problem for you?

  • Ah, I edited your message to improve formatting, and I was able to see the quadrupled backslashes (not slashes). I surrounded with the backtick character to make them visible (they were interpreted by Markdown, apparently).

    Well, the problem with the choice of backslash as file separator in Windows, is that in lot of languages, this character is interpreted as an escape, so it needs to be doubled to get its regular meaning.

    That's why we often advise not to write loadImage("C:\\data\\image.png") but rather loadImage("C:/data/image.png"): more readable, less keyboard gymnastic (backslash isn't very accessible on some non-US keyboards), always work.

    So I suppose the quadruple backslashes come from such escaping process.

    I suggest to replace all backslashes with regular slashes before sending the path, it would avoid any problem.

  • ok i understand the problem but how can i resolve this its not me that choose the backslash its the function selectInput() that call this backslash is that it has a solution to put the slash rather than the backslash

    sorry my english is poor thx a+

  • edited November 2013

    hi all i have receive an response on codelab forum this is how to reverse slash for pure data Chaine = join(split(pdFilePath, '\\'), "/");

    String pdFilePath = "file.wav";
    
        void fileSelected(File selection) {
          if (selection == null) {
            println("Window was closed or the user hit cancel.");
          } else {
            println("User selected " + selection.getAbsolutePath());
            pdFilePath =  join(split(selection.getAbsolutePath(), '\\'), "/");
          }
        }
    

    thx a+

Sign In or Register to comment.