Function that finds the absolute path of a file

Hi,
I'm creating an application using the SDL framework.
The following code gives me the absolute path for the file "caisse.jpg", which is located in my application bundle. Then, I can use the value of "cstrURL" to load the image with IMG_Load(cstrURL);
#import <CoreFoundation/CoreFoundation.h>
int main(int argc, char *argv[])
CFURLRef url = CFBundleCopyResourceURL( CFBundleGetMainBundle(),
CFSTR("caisse"),
CFSTR("jpg"), //extension du fichier
NULL );
const char* cstrURL = CFStringGetCStringPtr(
CFURLCopyFileSystemPath(url,kCFURLPOSIXPathStyle),
CFStringGetSystemEncoding()
printf("URL: %s", cstrURL);
return EXIT_SUCCESS;
But I have many files to load for my application. I tried to create a function that would take as parameter informations about the image, and then automatically find the absolute path of this image.
( void imgPath(char name[], char ext[], char destination[] ---> name = "image", ext = "jpg", destination is a variable in which the function puts the absolute path of the file)
How can I do that? What bugs me is the use of the CFSTR macro in the code I have...
Thank you very much
FRANKY

The CFSTR macro can only use a constant string as parameter, not a variable one.
You can use instead CFStringCreateWithCString if the parameter is a C String (char *).
Additionaly, I think the input parameters of your imgPath function must be of char* type, not char. And the output parameter char** (but it would be easier to know with the function source code).

Similar Messages

  • How to find the absolute path of file  which store in KM foler ?

    Hello everyone:
         We want to develop an ABAP program which can write files into KM folder directly.
         So I need to find the absolute path of file which store in KM folder first, then we can consider the develop solution.
         Is this issue possbile that an ABAP  program write files into KM folder  directly ?
         Is there anybody had done this job ?
    Best Regards,
    Jianguo Chen

    Hi,
    http://forum.java.sun.com/thread.jsp?forum=34&thread=36
    612The methods in the above topic seem to be available when use a DOM parser..

  • Finding the exact path of a file using a Java program

    Can anyone tell me how to find the exact path of a file which is saved in a directory other than the one in which the main file is saved? I know there is a class called File which has many methods like isAbsolutePath() and isPath() but they return the path in which the main class is located

    actually i m trying to write a program which will
    take a name of a file or a directory from the console
    and it should give the entire path of that file or
    directory and this file need not be stored in the
    path of the main class.....It can be stored in any
    drives of my PC....Ok, then the console input needs to be an absolute path or a path relative to some given directory (usually the one from which the application is started). Java cannot magically guess absolute paths if you just provide a file name. E.g. if I'd use your program and would provide as input "build.xml", how should the program know which file by that name I mean (there are lots of build.xml files in different locations on my machine)?

  • What is the absolute path of my file?

    Suppose my file is at the location
    C:\oc4j\j2ee\home\applications\r1\r1\WEB-INF\lib\us-english-v2-whole.dict
    what is the absolute path of this file.

    Congrats on 20k warner.
    Of course, if you're going to try to use that path in a String literal, you'll have to escape the backslashes
    String absPath = "C:\\blah...";In Java, most File I/O classes are smart enough to translate a path into one that works with your platform. So when using paths in say a File object, you can just use forward-slashes to be consistent and not have to escape them.

  • How to get the absolute path of a file from the local disk given the file n

    how to get the absolute path of a file from the local disk given the file name

    // will look for the file at the current working directory
    // this is wherever you start the Java application (cound be C: and your
    // application is located in C:/myapp, but the working dir is C:/
    File file = new File("README.txt"); 
    if (file != null && file.exists())
        String absolutePath = file.getAbsolutePath();

  • To get the absolute path of a file in JSP

    Hi,
    I want to include a HTML page in a jsp.The path of the jsp should not be hot coded.So that i can get the path from the jsp file i am running and then concat the correspondinghtml file name to the absolute path of the jsp file i am running.What can i do to get the absolute path of the jsp file.

    I dont know if there is a way to get the path of the current jsp - but you sure can get the path to your web application using the ServletContext's getRealPath() method and then if you have stored the html (say x.html) in a folder (called, say 'static') immediately under your application root,
    String contextPath = application.getRealPath("/"); //path to your application ctxt
    String htmlFilePath = contextPath.append("/static/x.html");ram.

  • How to find the physical path of a file

    Usually, one can use absFileNmae() method to find the path of a file in Java. The problem is that it may only return a mapped path when a Servlet or JSP is running in a special server. For example, when I run a servlet "MyProgram" in JRun, absFileName() only returns "c:\JRun\jsm-default\MyProgram", which is just a mapped path, not a real physical path.
    By the way, in ASP, one can use server.mapPath("MyASPProgram.asp") to obtain the real physical path of the file.
    Your solution is welcome.
    YC

    Usually, one can use absFileNmae() method to find the path of a file in Java. The problem is that it may only return a mapped path when a Servlet or JSP is running in a special server. For example, when I run a servlet "MyProgram" in JRun, absFileName() only returns "c:\JRun\jsm-default\MyProgram", which is just a mapped path, not a real physical path.
    By the way, in ASP, one can use server.mapPath("MyASPProgram.asp") to obtain the real physical path of the file.
    Your solution is welcome.
    YC

  • Finding the physical path of a file

    I'm developing a JSP webapp on www.mycgiserver.com and I need to open a XML file....but the standard method of
    ServletContext sc = getServletConfig().getServletContext();
    String realPath = sc.getRealPath("data\\repositoryData.xml");
    seems not to work. It gives me
    Real Path of data\repositoryData.xml: /usr/local/resin/doc/data/repositoryData.xml
    Which ends up giving me null pointer exceptions on my Document objects. I assume that means it's not finding any file at that location. What am I doing wrong?

    try:
    String rootContext = getServletContext().getRealPath();
    String servletPath = request.getServletPath();
    realPath = rootContext + servletPath //however, it's what ever the servlet-mapping element
    in your deployment descriptor is set too

  • Find the installation Path of the current running VM on Windows

    Hello,
    I have a java class started by webstart.
    In this class I would like to find the absolute path of the current running vm? This is important to me because I need to start an exe file (using ProcessBuilder) and hand it the path of the java VM,
    For example I could try something like this:
    private static File findJDK() throws Exception {
    String s = System.getProperty("java.home");
    File myJRE = new File(s);
    if (new File(myJRE, "bin/javac.exe").isFile()) {
    return myJRE;
    File parent = myJRE.getParentFile();
    if (new File(parent, "bin/javac.exe").isFile()) {
    return parent;
    for (String pathel : System.getenv("PATH").split(File.pathSeparator)) {
    File bindir = new File(pathel);
    if (new File(bindir, "javac.exe").isFile()) {
    return bindir.getParentFile();
    return myJRE;
    But I would like the above code to be more fool proof!
    For example the "java.home" could be wrongly set.
    Since java is allready running I would have hopped that I could query the Runtime. But there seems to be no method providing the running java VM path?
    I also tried looking at the jnlp services API but no luck.
    I would be also interested find the lastest java VM on the client Windows machine....
    Many greetings
    john

    http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getProperties()
    bye
    TPD

  • How to get the absolute path of logicalhost server domain on Windows Sun

    i am reading a file from Xsql Folder, that is located in the logicalhost Sun\AppServer\domains\domain1\applications\j2ee-apps.(IN Sun Application Server)
    I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
    i tried with System.getProperty("com.sun.aas.instanceRoot").
    but i am able to retrive Sun\AppServer\domains\domain1 upto this .i am unable to retrive Sun\AppServer\domains\domain1\applications\j2ee-apps.
    please suggest me how u can get absolute path in sun application server

    Take a look here

  • How to get the absolute path of logicalhost server domain on Windows?

    My logicalhost server domain behaves strangely. I am reading a file from collaboration definiton, that is located in the logicalhost/is/domains/domain1/config folder. I thought, that this folder is used as an application root folder so I can read files like ./file from there. And it worked.
    But then I've installed the domain as a Windows service, restarted the PC. When the domain1 gets started, I get exceptions saying that the file can't be found. Then I restart the domain (in domainmgr.bat) and it works again.
    I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
    And my second question is: Why does this happen?

    The default folder for a Windows Service is the system32 folder contrary to the instance root folder when starting it as a normal process.
    That's the why, haven't tried the how, but you should be able to get the value by calling System.getProperty("com.sun.aas.instanceRoot").
    Hope this helps
    Paul

  • Getting absolute path of a file running in remote machine

    Hi,
    I want to get the absolute path of a file that will be created in the remote server. Inside a directory XYZ in remote machine, the file will be created and the remote machine's address is xxx.xx.x.x. I have used the following snippet
    File f=new File(Filename);
    f.getAbsolutePath();
    Now, in the output am getting the absolute path of the file as d:/XYZ/Filename. Is there any way to get the output as xxx.xx.x.x/XYZ/FileName ? Can someone please suggest why the server details are not fetched and instead the directory name is fetched.
    I am running the program to get absolute path of a file in my remote machine. and for accessing that remote file from my machine, I use xxx.xx.x.x/XYZ/FileName.
    Thanks in advance.

    I'm going to take it a step further and guess at what the OP is going to say next.
    On host w.x.y.z there's a file /a/b/share/some_dir/file.txt.
    Host w.x.y.z is sharing the /a/b/share/ directory as SHARE.
    Client mounts \\w.x.y.z\SHARE as D:, so that he sees D:/some_dir/file.txt.
    OP now wants to know not just that D:/some_dir/file.txt is \\w.x.y.z\SHARE/some_dir/file.txt, but also wants to know that on w.x.y.z, SHARE corresponds to /a/b/share.
    @OP: If that's what you want, forget it. Part of the premise of file common drive/directory sharing protocols is that the client does not know or care and does not need to know or care what the absolute path is on the serving host. It's none of his business.

  • Get absolut path of a file

    when I write to a file in the actuel directory,
    e.g fw = new FileWriter("file.txt");
    how I can get the absolute path of this file? (e.g. C:\dir\file.txt)
    thanks stn

    Captain Obvious says ..... File.getAbsolutePath();
    Thank you, Captain Obvious.

  • Getting absolute path of a file in a webapp without using servlet/JSP

    Hi all,
    I need a small clarification. Is it possible to reterive the absolute path of a file present in a tomcat web application without using Servlet/JSP. I have a normal java class which uses this file to read the configuration parameters. I like to know whether I need to create a seperate servlet which will read the parameters from web.xml.

    Hi all,
    I need a small clarification. Is it possible to
    reterive the absolute path of a file present in a
    tomcat web application without using Servlet/JSP. What if the file is in a WAR? What do you do then?
    I
    have a normal java class which uses this file to
    read the configuration parameters. There are other, better ways to do this.
    I like to know
    whether I need to create a seperate servlet which
    will read the parameters from web.xml.What do you really want it for? You shouldn't need an absolute path. Use the class loader to get an InputStream.
    %

  • I am trying to update my iTunes but it keeps saying that it cannot find the correct path...Any suggestions?

    I  am trying to update my iTunes but it keeps saying that it cannot find the correct path...Any suggestions?

    Hey b.elyse
    Check out the following article that will assist with removing iTunes. Make sure to follow the order to ensure that it removed properly.
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
    http://support.apple.com/kb/ht1925
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

Maybe you are looking for