Make a Directory

Help with writing and running scripts

Make a Directory

Postby jtrelfa » Mon Oct 19, 2009 1:44 pm

I have to take 3 files and make 48 copies of each file - changing 3 key pieces of data in each file.

I don't particularly want to do this manually - so I created a script. It works except - I want to put each new file into it's own directory.

Example:

c:\files\directory_1\file.txt

open the file, change the data, save the file as:

c:\files\directory_2\file.txt

do it over and over again until all 48 files have been created

If directories 2 through 48 don't exist... is there a script command to create the directory I need?

Thanks,
Jon
User avatar
jtrelfa
Newbie
 
Posts: 6
Joined: Wed Aug 16, 2006 11:00 pm

Re: Make a Directory

Postby Mofi » Tue Oct 20, 2009 12:29 am

No, there is no command to create directories. UltraEdit is a text editor and not a file manager. However, you can do this if you first configure a user tool in Advanced - Tool Configuration with following parameters:

On tab Command:
Menu Item Name: Create Directory
Command Line: md %sel%
Working Directory: let it empty
Toolbar bitmap/icon (file path:) file name of an appropriate *.bmp or *.ico file or let it empty

On tab Options:
Program Type: Dos Program
Save Active File: unchecked
Save all files first: unchecked

On tab Output:
Command Output: Append to Existing
Show DOS Box: unchecked
Capture Output: unchecked
Replace selected text with: No Replace

Now you can use in your script:

UltraEdit.newFile();
UltraEdit.activeDocument.write(String variable with the directory to create);
UltraEdit.activeDocument.selectToTop();
UltraEdit.RunTool("Create Directory");
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);

Because you need to run the tool to create the directory several times, it would be better to create the new file first, remember its document index, make this temporary file active before writing the directory path into it and calling the user tool and finally close the temporary file before exiting the script.

// Somewhere at start of your script:
nTempFileIndex = UltraEdit.document.length;
UltraEdit.newFile();

// Whenever you need to create a directory:
UltraEdit.document[nTempFileIndex].setActive();
UltraEdit.activeDocument.selectAll();
UltraEdit.activeDocument.write(String variable with the directory to create);
UltraEdit.activeDocument.selectToTop();
UltraEdit.RunTool("Create Directory");

// Somewhere at end of your script:
UltraEdit.closeFile(UltraEdit.document[nTempFileIndex].path,2);

Note: It is important that the temporary file is the active file before calling the user tool. %sel% is replaced always by the selected text in the active document only.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Scripts