Make a Directory

Make a Directory

6
NewbieNewbie
6

    Oct 19, 2009#1

    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

    6,686585
    Grand MasterGrand Master
    6,686585

      Oct 20, 2009#2

      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.
      Best regards from an UC/UE/UES for Windows user from Austria