This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Easy scripting console question: How do I see what directory its in?

Other Parts Discussed in Thread: CCSTUDIO

There have been several instances where I'm trying to access a file (like a .out or .dat to download to memory) and I get the dreaded

Could not open file

Is there a way to tell what directory the scripting console is in?

For example, I have a linked project to a clearcase view on d:, and my workspace is on C:. The .out file is in d. So I try to set the current directory and I get an error (see below)

js:> env.setCurrentDirectory("D:\vws\ejp_M2_evm6472_pwcw\spDsp\EVM\M2_EVM6472");
Could not set Current Directory, "D:\vws\ejp_M2_evm6472_pwcw\spDsp\EVM\M2_EVM6472_configuration\.config\xconfig_message_single\D: wsejp_M2_evm6472_pwcwspDspEVMM2_EVM6472" does not exist

Yet its there!! (at least according to the DOS window)

D:\vws\ejp_M2_evm6472_pwcw\spDsp\EVM\M2_EVM6472>dir
 Volume in drive D has no label.
 Volume Serial Number is 44D3-F14D

 Directory of D:\vws\ejp_M2_evm6472_pwcw\spDsp\EVM\M2_EVM6472

08/26/2010  10:29 AM    <DIR>          .
08/26/2010  10:29 AM    <DIR>          ..

I rebooted CCS and tried again. The error suggests that somehow setCurrentDirectory is appending a default directory somehow.

js:> env.setCurrentDirectory("c:\Work")
Could not set Current Directory, "C:\Program Files\Texas Instruments\ccsv4\eclipse\D: wsejp_M2_evm6472_pwcwspDspEVMM2_EVM6472\c:Work" does not exist

Cheers

 

  • Hi Eddie,

    From the error message, the setCurrentDirectory is referring to a path without the slashes. You have to escape the slash or use "/" in your path.

    Regards,
    Patrick

  • Thanks a bunch Patick.

    What command can I use to see what directory the scripting console is looking at?

    Also, where can I find documentation on env class?

    Cheers

  • Eddie said:
    Also, where can I find documentation on env class?

    env = ScriptingEnvironment

    <INSTALL DIR>/ccsv4/scripting/docs/DS_API/com/ti/ccstudio/scripting/environment/ScriptingEnvironment.html

  • In that doc, you'll see that there is an API "getCurrentDirectory()"

  • Yup, works great

    print(env.getCurrentDirectory())

    Thanks a bunch guys. You are a great help. (especially to the Java illiterate)

     

     

     

  • Hi

    Hope you java guru's are still watching this thread.

    How do I list the files in the directory env.getCurrentDirectory()?

    Couldn't find anything in the API doc

    C:\Program Files\Texas Instruments\ccsv4\scripting\docs\DS_API\com\ti\ccstudio\scripting\environment\ScriptingEnvironment.html

    (sorry for going on and on and on with this)

    Cheers

  • I dont' know if there is something to do this in JavaScript, however, you can use the java.io.File class to do what you need.

    you can use this snippet

    importPackage(Packages.java.io)

    files = new File(<directory>).listFiles() // files is an array

    hope this help.

  • Hi Eddie,

    I've written a little custom console command for you. Take the attached txt file, rename to .js extenstion. The load it in the scripting console using loadJSFile. Then run the command 'listDir' in you console. The argument is the directory to list.

    Ex:

    listDir("C:/")

    listDir(env.getCurrentDirectory() )

    If you do a 'help' on the command, it will give you the argument description also.

    You can modify the command to default to the current directory if no argument is passed in. Up to you.

    Have fun!

    ki

  • importPackage(Packages.java.lang)
    importPackage(Packages.java.io)
    
    /**
     * Displays the contents of a directory
     * @param string Directory to list contents for
     */
    function listDir(path)
    {
        // Directory path here
        var path;
        var i;
        var file;
    
        if(path == ".")
            path = env.getCurrentDirectory();
    
        var folder = new java.io.File(path);
    
        var listOfDir = folder.list();
    
        for (i = 0; i < listOfDir.length; i++)
        {
            file = listOfDir[i];
            print(file);
        }
    }
    

    Awesome!

    You also answered my next question on how to add help to the javascript.

    I added a change so that you can do listDir(".")

    Cheers