Author Topic: Macro to list all files in a project  (Read 5472 times)

rdsuel

  • Community Member
  • Posts: 10
  • Hero Points: 0
Macro to list all files in a project
« on: March 24, 2009, 02:08:07 PM »
I'm using slick v11.0.2 and I'm trying to find a macro that will list all of the files in my project as text.  I'd like to copy all of the file names and past them into excel. 

Does such a macro exist, or do I need to write one?

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Macro to list all files in a project
« Reply #1 on: March 24, 2009, 05:36:34 PM »
I don't know one off the top of my head, but (at least in SE 12 and higher) the Slick-C function GetProjectFiles copies the project files into a specified buffer.  You could look for callers of that to find if such a macro exists, or copy what one of the callers does to write a (small) macro yourself.

rdsuel

  • Community Member
  • Posts: 10
  • Hero Points: 0
Re: Macro to list all files in a project
« Reply #2 on: March 24, 2009, 05:56:24 PM »
Thanks for the info.  I went ahead and wrote a macro to do what I want.  I'm pasting the code in case others find this useful.

-Rick

Code: [Select]
#include "slick.sh"

/*******************************************************************************
//
// Function    :  list_project_files
// Parameters  :  Options: P=Path, D=Drive, E=Extension, N=Name.
// Returns     :  none
//
// Description :  This macro displays a list of all files in the current project
//                in a new temp buffer.  Specifying the Options string allows
//                the way the filenames are displayed to be modified.  These
//                options are passed directly to the strip_filename() function.
//
//                For example:
//                list_project_files "PD" - strips the directory and path from
//                 the file names.
//                list_project_files - displays the all of the files with the
//                 full paths.
// ____________________________________________________________________________
// Author      :  Rick Suel
// History     :  03/24/2009 - Function Created (RDS)
//
*******************************************************************************/
_command void list_project_files(_str Options="")  name_info(',' VSARG2_MACRO | VSARG2_REQUIRES_EDITORCTL | VSARG2_READ_ONLY)
{
   _str FileNameArray[]; 
   _str line;
   int orig_window_id = p_window_id;   
   int temp_window_id;

   // Ensure there is a project loaded.
   if (_project_name != '')
   {
      // There is currently an open project, proceed.

      // Convert options to upper case.
      Options = upcase(Options);

      //-----------------------------------------------
      // Save the list of filenames in the project.
      //-----------------------------------------------
      // GetProjectFiles will get all files in the given project and will add them
      // to a temporary buffer (temp_view_id), one filename per line
      status = GetProjectFiles(_project_name, temp_window_id);

      // If the project file retrieval was successful (status = 0), continue...
      if (!status)
      {
         // Make the temp buffer with the file names the active buffer.
         p_window_id = temp_window_id;
         // Move to the top of the buffer.
         top();up();
         // Loop through the lines of the buffer and create an array of file names.
         for (i = 0; !down(); i++)
         {
            // Retrieve the current line from the buffer into the line variable.
            get_line(line);                                                 
            // Strip the filename from the string using the options that were passed in.
            FileNameArray[i] = strip_filename(line, Options);
         }

         // Create a new buffer for displaying the file names.
         e( "FileListResults.txt" );
         // Loop through the file name array and add each name to the buffer.
         for (i=0; i<FileNameArray._length(); i++)
         {
            insert_line(FileNameArray[i]);
         }

         // Restore the original Window ID.
         p_window_id = orig_window_id;
         // Delete the temp buffer.
         _delete_temp_view(temp_window_id);
      }

   }
   else
   {
      _message_box('This macro requires a project to be open.');
   }
}

Absinthe

  • Guest
Re: Macro to list all files in a project
« Reply #3 on: September 18, 2009, 04:59:52 PM »
I haven't run your macro, but is there any reason why the following wouldn't do it?
Quote
_command list_proj_files()
{
   _str cwd='-VDP '_ProjectGet_WorkingDir (_ProjectHandle (_project_name));
   list  (cwd);
}