[texworks] SCRIPTING: Get content of specified directory

Paul A Norman paul.a.norman at gmail.com
Sun May 15 12:22:00 CEST 2011

Dear Henrik,

Not so far as far as I know.

As you have, I've been using system calls to things like  "cmd /c
mkdir \""+ documentPath +"images\""
Can switch case on
http://twscript.paulanorman.com/docs/html/files/platform.html and
prepare differnt statements for the TW.system call.

(see subheadngs in and under main headings "User 'Library' Modules and
helper objects"  at
http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.htm for
some explanation on twPan - recomend downloading from
http://twscript.paulanorman.com/docs/index.html and the .chm there.)

and  have been using things like ...

  function  chooseFromDirectoryListing(Description, pathDir, fileExtension)
  // pathDir (no trailing slash), fileExtension with . E.g.  .txt

   //     TW.app.clipboard = "cmd /c dir /b  \""
                          +  pathDir + "\\*" + fileExtension + "\"";

      var fileList = twPan.osCmd("cmd /c dir /b  \""
                          +  pathDir + "\\*" + fileExtension + "\""
                             , true)

          removeExtnsn = new RegExp(fileExtension,"ig");

        fileList = fileList.replace(removeExtnsn,"").split(lineBreak);

  //    var chosenAnswer =
            //   twPan.select(Description, fileList);

 var chosenAnswer =    TW.getItem(null, Description, Description, fileList);

        if (twPan.emptyString(chosenAnswer) == false)
          chosenAnswer = chosenAnswer + fileExtension;

      return chosenAnswer;

You can use


See also notes in

Can get one or multi-select more file names though returns an array in
that case, requires User interaction though.


On 15 May 2011 21:26, Henrik Skov Midtiby <henrikmidtiby at gmail.com> wrote:
> Hi
> >From at script would I like to get access to the contents of the
> current directory.
> This information should be used for autocompleting filenames for
> includegraphics and input macros in latex.
> I know it is possible to access the commandline and issue an 'ls -all'
> or something similar, but is this information also available directly
> in QtScript?
> Best regards,
> Henrik Skov Midtiby

More information about the texworks mailing list