Previous Next Chapter

Creating a Script to Move Files

AmigaDOS does not have a Move command. Normally, there are two ways of moving a file with AmigaDOS: a RENAME command or a combination of COPY and DELETE commands.

Using RENAME to move a file is possible only when moving the file to a destination on the same volume. Attempting to rename across devices causes an error. The copy-and-delete method works in any situation, but is cumbersome.

To create a Move command that lets you move a file within or accross devices with a single command, create a script with the following commands:

1> RUN ED S:Move+
PROTECT S:Move swrd

Enter these commands in the ED window:

.KEY source/A, to/A
.BRA {
.KET }
FAILAT 21
RENAME >NIL: {source} TO {to}
IF WARN
COPY {source} TO {to}
IF WARN
ECHO "The file {source} could not be moved."
QUIT 20
ENDIF
DELETE {source} QUIET
ENDIF
ECHO {source} "has been moved to" {to}

Save the script and exit ED. The s protection bit is automatically set after you exit.

Use this script the same as you would use a command. Enter MOVE followed by two arguments: the current path of the file to move and the path to the desired location.

Deleting with Interactive DIR

The DIR command has an interactive mode that pauses after each file or directory it lists and allows you to enter one of several simple commands. One option is to delete the item, which can be useful in certain situations.

For example, if you accidentally name a file #? (the wildcard combination that matches anything), attempting to delete it through normal methods is inadvisable. This is because DELETE #? Deletes everything in the directory, including any other valuable files that are there.

The interactive DIR can solve this problem and be used as a general-purpose query/delete tool. This is helpful when you have a large directory containing many items to delete, but the file names do not have enough in common to make a pattern matching DELETE practical.

To delete various files on a disk called Debris safely with an interactive DIR, enter:

1> DIR Debris: INTER

DIR lists the names of the files in Debris alphabetically one by one, each followed by a question mark prompt. Press Return to go to the next file or E to enter a directory. When the name of an unwanted file appears, enter DEL to delete the file. Enter Q to leave the interactive DIR.

Generating Scripts with LIST LFORMAT

One of the prime uses of the LIST command's LFORMAT option is for automatically creating scripts used to process a series of files. You can produce a raw script using a LIST statement with LFORMAT, a TO argument to redirect the LIST output to a file, and pattern matching. You can then view the script and edit it manually if necessary before executing it.

To create a script that renames all the files in the current directory, adds the extension .IFF to their present file names, and places them in a directory called Paintfiles in the Work partition:

1> LIST #? TO T:renamer LFORMAT="RENAME %P%N TO Work:Paintfiles/%N.IFF"

Enter ED T:renamer to check the script, which should resemble the following. If the match pattern lists files that you did not want processed or your LFORMAT string does not work as expected, you can edit the script or modify and reenter the command.

RENAME Paint:Vince TO Work:Paintfiles/Vince.IFF
RENAME Paint:Henro TO Work:Paintfiles/Henri.IFF
RENAME Paint:Paul TO Work:Paintfiles/Paul.IFF
RENAME Paint:Pablo TO Work:Paintfiles/Pablo.IFF
RENAME Paint:Andy TO Work:Paintfiles/Andy.IFF

When the script is correct, leave ED and enter EXECUTE T:renamer .

See the "Recursive AmigaDOS Command Script" example for a more advanced use of LIST LFORMAT.

Customizing LITS Output

You can also use LFORMAT to customize the output of LIST for special purposes. Save the line as an alias to make it easier to use in the future.

To create an alias for LIST that displays information only on files created since the date you enter, with the date first and protection bits and time omitted:

1> ALIAS lsince LIST FILES SINCE [] LFORMAT="%D%-25N %L"

If the current directory is S:, the output of lsince 01-sep-92 would be similar to this:

19-Oct-92 PCD 715
30-Nov-92 Startup-sequence 1360
Friday Shell-startup 671
Yesterday User-startup 609

Using ICONX to Run Scripts

If you prefer to work with the mouse whenever possible or you are setting up an Amiga for a Workbench-only user, ICONX is useful. Using C:ICONX as the Default Tool of a project icon lets you run a script (or a command that lacks a Workbench interface) from the icon. It lets you start the script by opening the icon, as if the script were a standard Workbench tool.

There are also advantages to starting programs this way for the advanced user, including scripting preparatory steps (such as loading special Preferences presets) before launching a program and allowing the program's task priority to be changed easily. The following example demonstrates these techniques.

To start an application called OldApp from an ICONX icon, first loading a special Preferences font preset, and adjusting the application's task priority, create this script for the icon:

CD SYS:
Prefs/Font FROM SYS:Prefs/Presets/defscrn.pre USE
CHANGETASKPRI -1
OldApp

Preventing Displayable Output From Scripts

In scripts, you often want to execute a command without the command displaying its usual Shell output. This can prevent an unnecessary series of messages or keep an output window from opening at an inopportune time.

To prevent all console output, redirect command output to a dummy destination with the >NIL: argument:

1> DELETE >NIL: T:Tempfile

The >NIL: argument prevents the printing of the message T:Tempfile Deleted , or any error messages.

To prevent console output except for error messages, use the QUIET option with those commands that support it:

1> DELETE T:Tempfile QUIET

The T:Tempfile Deleted message is not printed; however, if T:Tempfile does not exist, the No file to delete message appears.

Entering and Testing ARexx Macros

To make entering and testing ARexx macros simpler:

Enter the following AmigaDOS script and save it as S:Edrx:

.KEY mac
ED REXX:<mac>.rexx
PROTECT S:<mac>.rexx +S-E
RX REXX:<mac
>

Use this script when experimenting with ARexx macros. Enter Edrx followed bythe name of the macro. Edrx invokes the editor without you having to type in the .rexx extension and directly calls the ARexx interpreter RX with your macro as an argument when you exit.

Top Previous Next Chapter