How to get the current project folder path?

Help with writing and running scripts

How to get the current project folder path?

Postby bitchen » Fri Apr 16, 2010 9:42 pm

Hello
I modify the GetListOfFiles for the file search in my project folder. I do not know the method for get the automatic project folder path.
If anyone know the way, please let me know.

I want to auto set the value for "sFolder" in current project folder. Here is code.

Code: Select all
/*
   Original Script Name:   GetListOfFiles
   Creation Date: 2008-04-16
   Last Modified: 2009-02-20
   Copyright:     Copyright (c) 2009 by Mofi
   Original:      http://www.ultraedit.com/files/scripts/GetListOfFiles.js
                  http://www.ultraedit.com/forums/viewtopic.php?t=5442
   
   Modify for the project file search
   Script Name:   SearchFile
   Last Modified: 2010-04-17
   Modified by bitchen               
*/
function SearchFiles (nFileList, sDirectory, sFileType, bSubDirs)
{

   var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 2;

   if (typeof(nFileList) != "number" || nFileList < 0 || nFileList > 1) nFileList = 1;

   if (nFileList == 0)
   {
      // Search in a default directory (sFolder).
      UltraEdit.outputWindow.write("Search directory:  " + sDirectory);
      if (typeof(sFileType) != "string" || sFileType == "") sFileType = "";
      if (typeof(bSubDirs) != "boolean") bSubDirs = false;
      nFileList = 0;
   }
   else if (nFileList == 1)
   {  // Search in a specified directory?
      // If no directory specified, use current working directory.
      if (typeof(sDirectory) != "string" || sDirectory == "" ) sDirectory = ".\\";
      // Append a backslash if it is missing at end of the directory string.
      else if (sDirectory.match(/\\$/) == null) sDirectory += "\\";
      // Search for all files if no file type is specified.
     
      if (typeof(sFileType) != "string" || sFileType == "") sFileType = "*";
      if (typeof(bSubDirs) != "boolean") bSubDirs = false;
      nFileList = 0;
   }
   else
   {
      nFileList = 0;
      sDirectory = "";    // For the list of open, favorite, project
      sFileType = "";     // or solution files the other 3 parameters
      bSubDirs = false;   // have always the same default values.
   }

   // Remember current regular expression engine.
   var nRegexEngine = UltraEdit.regexMode;

   UltraEdit.ueReOn();

   UltraEdit.frInFiles.directoryStart=sDirectory;
   UltraEdit.frInFiles.filesToSearch=nFileList;
   UltraEdit.frInFiles.matchCase=false;
   UltraEdit.frInFiles.matchWord=false;
   UltraEdit.frInFiles.regExp=false;
   UltraEdit.frInFiles.searchInFilesTypes=sFileType;
   UltraEdit.frInFiles.searchSubs=bSubDirs;
   UltraEdit.frInFiles.unicodeSearch=false;
   UltraEdit.frInFiles.useOutputWindow=true;
   UltraEdit.frInFiles.find("");

   return true;

// End of function SearchFiles


/*** SearchFiles **************************************************************/

// Code to demonstrate the usage of the function SearchFiles.

var g_nDebugMessage=1;          // Enable debug messages with message boxes.
var nSearchIn=0;                // Stores users choice where to search.
var sFolder="Z:\\PROJECT\\";    // Stores the search root folder specified by the user.
var sFiles="";                  // Stores the search files/types specified by the user.
var bSubFolders=false;          // Stores the users choice for searching in subdirectories.
var nSubFolders = 1;

UltraEdit.outputWindow.showStatus=false;
UltraEdit.outputWindow.clear();
if (UltraEdit.outputWindow.visible == false) UltraEdit.outputWindow.showWindow(true);

//if (UltraEdit.document.length < 1)
//{
//   /* If no file is open the commands getValue and getString currently (UE v14.20.1)
//      do not open message boxes for user input and return always 0 respectively NULL.
//      As workaround open a new file and later close that file without saving. */
//   UltraEdit.newFile();
//}

nSearchIn = UltraEdit.getValue("Search in the project dir. (= 0) or in special dir.(= 1)?",1);

if (nSearchIn == 0)
{
   sFiles = UltraEdit.getString("Please enter the files/types to find:",1);
   if (sFiles == "") sFiles = "*";
   UltraEdit.outputWindow.write("Find files/types:  " + sFiles);   
   bSubFolders = true;
   var sUsersChoice = bSubFolders ? "true" : "false";
   UltraEdit.outputWindow.write("Search subfolders: " + sUsersChoice);   
}
else if (nSearchIn == 1)
{
   UltraEdit.outputWindow.write("Get list of files: in directory");
   sFolder = UltraEdit.getString("Please enter the path to the directory:",1);
   if ((sFolder == "") || (sFolder == ".\\"))
   {
      UltraEdit.outputWindow.write("Search directory:  .\\ (= working directory)");
   }
   else
   {
      UltraEdit.outputWindow.write("Search directory:  " + sFolder);
   }
   sFiles = UltraEdit.getString("Please enter the files/types to find:",1);
   if (sFiles == "") sFiles = "*";
   UltraEdit.outputWindow.write("Find files/types:  " + sFiles);
   nSubFolders = UltraEdit.getValue("Search in subdirectories (0/1 = no/yes)?",1);
   if (nSubFolders) bSubFolders = true;
   var sUsersChoice = bSubFolders ? "true" : "false";
   UltraEdit.outputWindow.write("Search subfolders: " + sUsersChoice);
}

SearchFiles(nSearchIn,sFolder,sFiles,bSubFolders);
bitchen
Newbie
 
Posts: 4
Joined: Fri Apr 16, 2010 9:19 pm
Location: Korea

Re: How to get the current project folder path?

Postby Mofi » Sat Apr 17, 2010 12:15 pm

Why do you need the project folder path. If a project is open you can simply search in all project files. When you do that manually using Search - Find in Files and selecting Project Files you will see that In Files/Types and Directory are disabled because not required. UltraEdit/UEStudio use automatically the project files list. It does not matter if the project uses groups with manually added files or folders with filter to find project files dynamically.

Do you have files in your project folder and its subfolders which are not project files and you want nevertheless search something in those files, too?

There is no direct access to the UltraEdit internal string variable containing the project folder path of the opened project. There are some workarounds for getting the project folder path, for example by using a project tool which just returns the project folder path. But first check if you really need to know the project folder path.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4056
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: How to get the current project folder path?

Postby bitchen » Sun Apr 18, 2010 4:24 am

Dear Mofi.

I can not remember all of files in my project.(over the number of 1000 files.)
I want to know easy way like search files in project the Source Insight with the UE.
(File search in this case mean is where is the file in my project folders.)
Please let me know.
bitchen
Newbie
 
Posts: 4
Joined: Fri Apr 16, 2010 9:19 pm
Location: Korea

Re: How to get the current project folder path?

Postby Mofi » Sun Apr 18, 2010 12:43 pm

Ah, now I understand. You write a script to find files using command Find In Files. I can offer 3 methods:

1. Using just a user or project tool.

You configure a user or project tool with following settings:

On tab Command:

Menu Item Name: Find File (for example)
Command Line: dir /b /s "%sel%" (or "%modify%")
Working Directory: %rp
Toolbar bitmap/icon: (let it empty or browse to a BMP or ICO file)

On tab Options:

Program Type: Dos Program
Save Active File: unchecked
Save all files first: unchecked

On tab Output:

Command Output: Output to List Box
Show DOS Box: unchecked
Capture Output: checked
Replace selected text with: No Replace



2. Using a user or project tool + a script.

A user or project tool is required to get the values of the project variables into a new edit window, or the output window, or to Windows clipboard using additionally a third party tool like clip.exe from Microsoft (search WWW for "clip.exe" microsoft). For configuration details about that user tool see macro to find current project. This tool is executed from within the script using command runTool. After getting the project path (from edit window, output window or clipboard), you can run frInFiles.find("").

Of course you can also run the tool from my first suggestion from within the script to get the file names and use the script for opening the files.



3. A pure script solution

Your script uses:

UltraEdit.frInFiles.directoryStart="";
UltraEdit.frInFiles.filesToSearch=3;
UltraEdit.frInFiles.matchCase=false;
UltraEdit.frInFiles.matchWord=false;
UltraEdit.frInFiles.regExp=false;
UltraEdit.frInFiles.searchInFilesTypes="";
UltraEdit.frInFiles.searchSubs=true;
UltraEdit.frInFiles.unicodeSearch=false;
UltraEdit.frInFiles.useOutputWindow=true;
UltraEdit.frInFiles.find("");

to get a list of all project files into the output window. The content of the output window is copied to a user clipboard (clipboard 9). This large string containing one full file name per line is searched for the file name with a regular expression using method match(). The strings found by function match() are written to the cleared output window.



By the way: Do you have noticed command File - Quick Open, best executed with shortcut Ctrl+Q? It is a very useful command to quickly open a file from a large project when just a part of the name is known and not full name or in which directory a file is stored. It is also very useful to open several files at once. Press Ctrl+Q to open the dialog of this command and press key F1 to get help about this command. Give this command a try. It is a very nice feature.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4056
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: How to get the current project folder path?

Postby bitchen » Sun Apr 18, 2010 7:40 pm

wow!.
your solution is great!
Thank you very much. Mofi.
:D
bitchen
Newbie
 
Posts: 4
Joined: Fri Apr 16, 2010 9:19 pm
Location: Korea

Re: How to get the current project folder path?

Postby bitchen » Mon Apr 19, 2010 11:11 am

I use the methods for find files in my project. (Thanks Mofi. :) )
I do not know my script file is surplus code or not.
but I have some choice for find files with UE. so I am happy..

Hear is my final script file.
I selected the method of "2.Using a user or project tool + a script."
So First of all, make the project tool as follows.

On tab Command:

Menu Item Name: Get Project Path (for example)
Command Line: echo %rp
Working Directory: (let it empty)
Toolbar bitmap/icon: (let it empty or browse to a BMP or ICO file)

On tab Options:

Program Type: Dos Program
Save Active File: unchecked
Save all files first: unchecked

On tab Output:

Command Output: Output to List Box
Show DOS Box: unchecked
Capture Output: checked
Replace selected text with: No Replace

Code: Select all
/*
   Original Script Name:   GetListOfFiles
   Creation Date: 2008-04-16
   Last Modified: 2009-02-20
   Copyright:     Copyright (c) 2009 by Mofi
   Original:      http://www.ultraedit.com/files/scripts/GetListOfFiles.js
                  http://www.ultraedit.com/forums/viewtopic.php?t=5442
   
   Modify for the project file search
   Script Name:   SearchFile
   Last Modified: 2010-04-20
   Modified by bitchen               
*/
function SearchFiles (nFileList, sDirectory, sFileType, bSubDirs)
{

   var nOutputType = (typeof(g_nDebugMessage) == "number") ? g_nDebugMessage : 2;

   if (typeof(nFileList) != "number" || nFileList < 0 || nFileList > 1) nFileList = 1;

   if (nFileList == 0)
   {
      // Search in a default directory (sFolder).
      UltraEdit.outputWindow.write("Search directory:  " + sDirectory);
      if (typeof(sFileType) != "string" || sFileType == "") sFileType = "";
      if (typeof(bSubDirs) != "boolean") bSubDirs = false;
      nFileList = 0;
   }
   else if (nFileList == 1)
   {  // Search in a specified directory?
      // If no directory specified, use current working directory.
      if (typeof(sDirectory) != "string" || sDirectory == "" ) sDirectory = ".\\";
      // Append a backslash if it is missing at end of the directory string.
      else if (sDirectory.match(/\\$/) == null) sDirectory += "\\";
      // Search for all files if no file type is specified.
     
      if (typeof(sFileType) != "string" || sFileType == "") sFileType = "*";
      if (typeof(bSubDirs) != "boolean") bSubDirs = false;
      nFileList = 0;
   }
   else
   {
      nFileList = 0;
      sDirectory = "";    // For the list of open, favorite, project
      sFileType = "";     // or solution files the other 3 parameters
      bSubDirs = false;   // have always the same default values.
   }

   // Remember current regular expression engine.
   var nRegexEngine = UltraEdit.regexMode;

   UltraEdit.ueReOn();

   UltraEdit.frInFiles.directoryStart=sDirectory;
   UltraEdit.frInFiles.filesToSearch=nFileList;
   UltraEdit.frInFiles.matchCase=false;
   UltraEdit.frInFiles.matchWord=false;
   UltraEdit.frInFiles.regExp=false;
   UltraEdit.frInFiles.searchInFilesTypes=sFileType;
   UltraEdit.frInFiles.searchSubs=bSubDirs;
   UltraEdit.frInFiles.unicodeSearch=false;
   UltraEdit.frInFiles.useOutputWindow=true;
   UltraEdit.frInFiles.find("");

   return true;

// End of function SearchFiles


/*** SearchFiles **************************************************************/

// Code to demonstrate the usage of the function SearchFiles.

var g_nDebugMessage=1;          // Enable debug messages with message boxes.
var nSearchIn=0;                // Stores users choice where to search.
var sFolder="";                 // Stores the search root folder specified by the user.
var sFiles="";                  // Stores the search files/types specified by the user.
var bSubFolders=false;          // Stores the users choice for searching in subdirectories.
var nSubFolders = 1;
var sProjectFolder;

UltraEdit.outputWindow.showStatus=false;
UltraEdit.outputWindow.clear();
if (UltraEdit.outputWindow.visible == false) UltraEdit.outputWindow.showWindow(true);

if (UltraEdit.document.length < 1)
{
   /* If no file is open the commands getValue and getString currently (UE v14.20.1)
      do not open message boxes for user input and return always 0 respectively NULL.
      As workaround open a new file and later close that file without saving. */
   UltraEdit.newFile();
}

nSearchIn = UltraEdit.getValue("Search in the project dir. (= 0) or in special dir.(= 1)?",1);

if (nSearchIn == 0)
{
   UltraEdit.runTool("Get Project Path");
   UltraEdit.outputWindow.copy();
   sProjectFolder = UltraEdit.clipboardContent;
 
   if(typeof(sProjectFolder) != "string" || sProjectFolder == "") sProjectFolder = ".\\";
   else if (sProjectFolder.match("ECHO") != null) sProjectFolder = ".\\";
   sFolder = sProjectFolder;
     
   sFiles = UltraEdit.getString("Please enter the files/types to find:",1);
   if (sFiles == "") sFiles = "*";
   UltraEdit.outputWindow.write("Find files/types:  " + sFiles);   
   bSubFolders = true;
   var sUsersChoice = bSubFolders ? "true" : "false";
   UltraEdit.outputWindow.write("Search subfolders: " + sUsersChoice);   
}
else if (nSearchIn == 1)
{
   UltraEdit.outputWindow.write("Get list of files: in directory");
   sFolder = UltraEdit.getString("Please enter the path to the directory:",1);
   if ((sFolder == "") || (sFolder == ".\\"))
   {
      UltraEdit.outputWindow.write("Search directory:  .\\ (= working directory)");
   }
   else
   {
      UltraEdit.outputWindow.write("Search directory:  " + sFolder);
   }
   sFiles = UltraEdit.getString("Please enter the files/types to find:",1);
   if (sFiles == "") sFiles = "*";
   UltraEdit.outputWindow.write("Find files/types:  " + sFiles);
   nSubFolders = UltraEdit.getValue("Search in subdirectories (0/1 = no/yes)?",1);
   if (nSubFolders) bSubFolders = true;
   var sUsersChoice = bSubFolders ? "true" : "false";
   UltraEdit.outputWindow.write("Search subfolders: " + sUsersChoice);
}

SearchFiles(nSearchIn,sFolder,sFiles,bSubFolders);
bitchen
Newbie
 
Posts: 4
Joined: Fri Apr 16, 2010 9:19 pm
Location: Korea


Return to Scripts