How to do things
AI Noob vs. Pro

List biggest files
List newest files
Show subdir sizes
Search in files
Replace word in files
List dir differences
Send files in LAN

Free Open Source:

Swiss File Knife

a command line
multi function tool.

remove tabs
list dir sizes
find text
filter lines
find in path
collect text
instant ftp or
http server
file transfer
send text
patch text
patch binary
run own cmd
convert crlf
dup file find
md5 lists
fromto clip
hexdump
split files
list latest
compare dirs
save typing
trace http
echo colors
head & tail
dep. listing
find classes
speed shell
zip search
zip dir list

Depeche View
Source Research
First Steps

windows GUI
automation

command line
file encryption

free external tools,
zero install effort,
usb stick compliant:

zip and unzip
diff and merge
reformat xml
reformat source

cpp sources

log tracing
mem tracing
hexdump
using printf

articles

embedded
stat. c array
stat. java array
var. c array
var. java array
view all text
as you type
surf over text
find by click
quick copy
multi view
find nearby
fullscreen
bookmarks
find by path
expressions
location jump
skip accents
clip match
filter lines
edit text
highlight
load filter
hotkey list
receive text
send in C++
send in Java
smooth scroll
touch scroll
fly wxWidgets
fly over Qt
search Java

Continue an SFK script at a different point, or stop the script due to a condition with sfk if.
  • Download the free Swiss File Knife Base from Sourceforge.
  • Open the Windows CMD command line, Mac OS X Terminal or Linux shell.
  • OS X : type mv sfk-mac-64.exe sfk and chmod +x sfk then ./sfk
  • Linux: type mv sfk-linux-64.exe sfk and chmod +x sfk then ./sfk. OS X and Linux syntax may differ, check the help within the tool.
sfk ... +if [opts] expression command1 ... +command2
sfk ... +if ... [+]begin ... +elseif ... +else ... +endif

execute command1 if expression is true, then continue to command2.
if expression is not true, skip directly to command2.
can be used only in a command chain, after another command.

use "+if expr +begin ... +endif" to run multiple commands
as one block, if expression is true.

supported expressions

   return code comparison
   "rc=n"     return code of previous command equal  to   n
   "rc>n"     return code of previous command higher than n
   "rc<n"     return code of previous command lower  than n
   "rc<>n"    return code of previous comm.  not equal to n

   generic text or number comparison
   "l = r"    left part is equal to right
   "l <> r"   left part is not equal to right
   "l < r"    left part is lower  then right
   "l > r"    left part is higher then right
   "l <= r"   left part is lower  or equal
   "l >= r"   left part is higher or equal
   if both l and r contain only digits a numeric
   comparison is done, else a text comparison.

   logic values (since sfk 1.9.8.2)
   "1"        true, execute command or block
   "0"        false, skip command or block

options
   options for if must be given before expression.
   -var       use sfk variables, must be first option
   -text      force text comparison (nocase)
   -case      case sensitive text comparison
   -debug     tell what is done in a generic comparison

limited nesting
   if ... begin ... endif
   - may not contain other if[exist] / begin / endif
   - but may contain short if ... without begin.
   invalid nesting is not detected, and causes an undefined
   program flow. you may add global option -strictif to (try)
   to detect wrong if statements better.

do not forget 'begin' when using complex statements!
   sfk if ... begin ... +elseif ... +else ... +endif
   strictly requires the 'begin', otherwise it may do
   nothing, without any notice.

no chaining data support since sfk 1.9.3
   +if   does not accept any chain input data, as this
         creates ambiguities with many following
         commands, like +if ... +setvar a=text

see also
   sfk ifexist  check if a file or folder exists.
   sfk call     call sub functions in a script.
   sfk goto     jump to a local label.

examples
   sfk filter in.txt -+err +if "rc>0" run -yes "x.bat" +echo done
      if file in.txt contains the word "err", run x.bat.
      the "echo done" is always executed.

   sfk xex -justrc in.txt "/foo*bar/"
    +if "rc=0" stop 9 "[Red]error:[def] miss" +echo "match"
      type this all in one line, or use "sfk cmd 18". [18]
      if file in.txt does not contain the search pattern
      then stop with return code 9, printing an error.

   sfk -var echo "foo and bar" +setvar a
    +if "#(contains(a,'bar'))" tell "found bar" +tell "done"
      prints "found bar" and then "done", because the
      'contains' returns '1', causing command execution.

   sfk if 0 begin tell one +else tell two +endif +tell three
      prints 'two' and 'three'.
 
sfk ... +if [opts] expression command1 ... 
          +command2
sfk ... +if ... [+]begin ... +elseif ... 
          +else ... +endif

execute command1 if expression is true, 
then continue to command2. if expression
is not true, skip directly to command2. can
be used only in a command chain, after
another command.

use "+if expr +begin ... +endif" to run 
               multiple commands
as one block, if expression is true.

supported expressions

   return code comparison
   "rc=n"     return code of previous 
              command equal to n
   "rc>n"     return code of previous 
                 command higher than n
   "rc<n"     return code of previous 
                 command lower than n
   "rc<>n"    return code of previous 
                    comm. not equal to n

   generic text or number comparison
   "l = r"    left part is equal to right
   "l <> r"   left part is not equal 
                    to right
   "l < r"    left part is lower  
                 then right
   "l > r"    left part is higher 
                 then right
   "l <= r"   left part is lower  or 
                 equal
   "l >= r"   left part is higher or 
                 equal
   if both l and r contain only digits a 
   numeric comparison is done, else a text
   comparison.

   logic values (since sfk 1.9.8.2)
   "1"        true, execute command or block
   "0"        false, skip command or block

options
   options for if must be given before 
   expression. -var  use sfk variables,
   must be first option -text force
   text comparison (nocase) -case case
   sensitive text comparison -debug
   tell what is done in a generic
   comparison

limited nesting
   if ... begin ... endif
   - may not contain other if[exist] / 
     begin / endif
   - but may contain short if ... without 
   begin. invalid nesting is not detected,
   and causes an undefined program flow.
   you may add global option -strictif to
   (try) to detect wrong if statements
   better.

do not forget 'begin' when using complex 
statements!
   sfk if ... begin ... +elseif ... +else 
                          ... +endif
   strictly requires the 'begin', otherwise 
   it may do nothing, without any notice.

no chaining data support since sfk 1.9.3
   +if   does not accept any chain input 
         data, as this creates ambiguities
         with many following commands, like
         +if ... +setvar a=text

see also
   sfk ifexist  check if a file or folder 
                exists.
   sfk call     call sub functions in a 
                script.
   sfk goto     jump to a local label.

examples sfk filter in.txt -+err +if "rc>0" run -yes "x.bat" +echo done if file in.txt contains the word "err", run x.bat. the "echo done" is always executed. sfk xex -justrc in.txt "/foo*bar/" +if "rc=0" stop 9 "[Red]error:[def] miss" +echo "match" type this all in one line, or use "sfk cmd 18". [18] if file in.txt does not contain the search pattern then stop with return code 9, printing an error. sfk -var echo "foo and bar" +setvar a +if "#(contains(a,'bar'))" tell "found bar" +tell "done" prints "found bar" and then "done", because the 'contains' returns '1', causing command execution. sfk if 0 begin tell one +else tell two +endif +tell three prints 'two' and 'three'.

you are viewing this page in mobile portrait mode with a limited layout. turn your device right, use a desktop browser or buy the sfk e-book for improved reading.

 
sfk is a free open-source tool, running instantly without installation efforts. no DLL's, no registry changes - just get sfk.exe from the zip package and use it (binaries for windows, linux and mac are included).

 

the Daily Landscape image
the Daily Mobile Background