Standard Library/dir

From J Wiki
Jump to navigation Jump to search
Overview | android | break | colib | compare | coutil | dates | debug | dir | dll | files | jade | jal | stdlib | strings | sysenv | text | unxlib

This script defines directory utilities and is included in the J standard library. Definitions are loaded into the z locale.

Definitions

D dir, dircompare, dircompares, dirfind, dirpath, dirss, dirssrplc, dirtree, dirused

dircompare v compare files in directories
dircompares v compare files in directories
dirss v directory string search
dirused v get count and space of files in directory tree

dir (verb)

y = file specification
    if empty, defaults to *

x is optional:
  - if not given, defaults to 'n'
  - if character, returns a formatted directory,
      where x is the sort option:
        d=by date
        n=by name
        s=by size
  - if numeric, there are 1 or 2 elements:
        0{ 0= list short names
            1= boxed list of full pathnames
            2= full directory list
        1{ 0= filenames only (default)
            1= include subdirectories

subdirectories are shown first
filenames are returned in lower case

Example:

dir ''
1 dir jpath '~system/main/d*.ijs'

dirfind (verb)

Find name in directory

Syntax:

string dirfind directory

dirpath (verb)

Return directory paths starting from y

Optional x=0 all paths (default)
           1 non-empty paths (i.e. having files)

Example:

dirpath 'examples'

dirssrplc (verb)

Directory string search and replace.

Syntax:

(old;new) dirssrplc files

Example:

('old';'new') dirssrplc jpath '~system/main/*.ijs'

dirtree (verb)

Return filenames in directory tree as boxed matrix

Optional x is a timestamp to exclude earlier files.

Each row contains: filename;timestamp;size

Directory search is recursive through subdirectories

Filenames are returned in lower case in OSX or Windows

Ignores hidden directories

Global DirTreeX_j_ (set in session configuration) is a list of directories to exclude from the search. e.g. DirTreeX_j_=: 'cvs' to exclude cvs directories.

Example:

dirtree ''
dirtree 'main'
dirtree jpath '~system/packages/*.ijs'
2014 5 23 dirtree ''   - files dated on or after date.