FAR Batch Mode Examples

Return to FAR Batch Mode

You can write a script file to automate many of the commands found within FAR.  Giving your script file a .FarRun file extension (which is association with FAR.exe) allows you to simply double-click the script file to run it. If you don't use .FarRun (say .ini or .txt) then you will need to run the script file using FAR.exe command line and switches /B or /BB.

There are 3 ways to run the [default] script section in "MyBatchJob.FarRun" (see example below)

  1. Simply run "MyBatchJob.FarRun" from Explorer or from a command prompt

  2. Run FAR.EXE /O "c:\path\MyBatchJob.FarRun"

  3. Run FAR.EXE /BB:"c:\path\MyBatchJob.FarRun,default" /D:1 /L:d:\MyLogFile.txt

Note: Running a .FarRun file (1) by default executes the script in the [default] section. Use the /O open switch (2) if your computer does not have a .FarRun file association setup. The "Preference dialog > Explorer page" can be used to create or clear the association, however installing FAR will creates the association. The /BB switch (3) is more complicated but can be used if required.
 

Script file: MyBatchJob.FarRun

So lets look at a simple example called "MyBatchJob.FarRun" which we put together using NotePad.

[default]
;don't close FAR at end of search (optional)
/D:1
; set the log file name (optional)
/L:d:\MyLogfile.txt
; run to batch jobs
BatchCopy
DoFind1
DoFind2
zzz.ini,ScanFiles
zzz.ini,BatchCopy
This section contains a list of batch jobs to run (like a batch of batch jobs, hence the /BB command line switch). In this case we have 5 batch commands to run one after another. The first 3 commands are in the same file (see matching INI sections below). The other 2 commands are found in another file called zzz.ini.

Notice the /D:1 and /L:filename switches. These are used only when you run via a .FarRun file. If you run via the FAR.exe command line (/BB) then the switches need to be on the command line to work.

[BatchCopy]
drop_options=FileFilter
dirscan=C:\apps\Delphi6\Source
BackupTo=C:\Demo\Test
BackupTo_KeepAttributes=y
BackupTo_LogLevel=0
This batch job section (we called "BatchCopy") does the following. Sets the drop file filter using ini section [FileFilter] (below). Then scans the Delphi6 Sources folder for files (using the file filter). Then these files (now in the FAR file list) are copied to the c:\Demo\Test folder.
[DoFind1]
drop_options=FileFilter
dirscan=C:\Demo\Test
findstart='Begin'
replace= "begin"
\ '// comment'
Next we reload our file filter and scan for files in the new c:\Demo\Test folder. Although since the filter is the same as before we didn't really need to set the filter again. Then we replace all occurrences of the word "Begin" with "begin" + CRLF + "// comment". The \ (or /) in the next line tells FAR that the "replace=" text extends to a second line.
[DoFind2]
findstart='End'
replace= "end"
This section does yet another simple find and replace on the file list currently in FAR.
[FileFilter]
_opSkipDirs=1
_opSkipFiles=1
_opIncFiles=0
_opSkipDirsSL=_vti*|1|_private|1|
_opSkipFilesSL=.bak|1|.~*|1|
_opIncFilesSL=
The file filter section makes sense if you study the Drop File Filter Settings dialog in FAR. The dialog has 3 filter tabs, which can be enabled or disabled (notice the =1 and =0 settings here). So here we have effectively enabled the first 2 filter tabs. Each tab contains a checked list of file extensions. Here we build a list of items and check with |1| and uncheck using |0|.
Alternated Script

Note that commands that fill the file list (OpenFarList=, OpenFarSrch=, DIRSCAN=, DIR=) are special in that they can optionally coexist in sections with other commands. The general rule is one command per section. So lets now expand the number of sections so that each fill command has its own section (its up to you how you organize your script sections).

[default]
LoadSrcFiles
BatchCopy
LoadNewFiles
DoFind1

DoFind2

Here is the script above expand so that the Load File actions are now in their own sections. This maybe clarifies the script.

[LoadSrcFiles]
drop_options=FileFilter
dirscan=C:\apps\Delphi6\Source
Load files from the Delphi 6 Source folder using the FileFilter settings.
[BatchCopy]
BackupTo=C:\Demo\Test
BackupTo_KeepAttributes=y
BackupTo_LogLevel=0
Copy the files loaded into folder C:\Demo\Test
[LoadNewFiles]
drop_options=FileFilter
dirscan=C:\Demo\Test
Load the files from the new folder using FileFilter settings.
[DoFind1]
findstart='Begin'
replace= "begin"
\ '// comment'
Perform find and replace job 1 (on the files loaded from C:\demo\test).
[DoFind2]
findstart='Begin'
replace= "begin"
\ '// comment'
Perform find and replace job 2 (on the files loaded from C:\demo\test).
[FileFilter]
_opSkipDirs=1
_opSkipFiles=1
_opIncFiles=0
_opSkipDirsSL=_vti*|1|_private|1|
_opSkipFilesSL=.bak|1|.~*|1|
_opIncFilesSL=
Filter settings.

 

 


http://www.HelpwareGroup.com/