The object is used to work with file directories. It allows performing operations with directories stored on the disk: get directories inside a directory, parent directories, or all child directories, create a new directory or delete an existing one, and get files from a directory.

Type parameters

Hierarchy

Properties

Readonly code

code: string

App code of the URL’s target (the app’s code).

Readonly data

data: Based<Partial<DirectoryData>>

Values of object’s fields.

Readonly fields

fields: Readonly<object>

Description of the object’s fields.

Readonly id

id: string

ID of the URL’s target.

Readonly namespace

namespace: string

Namespace of the URL target (the code of the workspace that the app belongs to).

Methods

createChildren

  • The method creates a new directory in the current directory.

      // Example of creating a new directory in a user’s folder.  We need to get the user, get the directory, 
      and create a new directory  in it 
       let name = 'New directory name'; 
       const user = await System. users.getCurrentUser() 
       const searchDir = await System.directories. search(). 
           where(di =>di.__id.eq(user.data.__id)). 
           first();  
       const newDir = await searchDir.createChildren(name); 
    

    Parameters

    • name: string

      Name of the new directory.

    Returns Promise<DirectoryItem>

    Directory object.

delete

  • delete(): Promise<number>
  • The method deletes the current directory.

       // Example of deleting all directories created by a user  
       const searchDirs = await System.directories.search(). 
            where( di => di.__createdBy.eq('<some id>')). 
            all(); 
      for (let i = 0;  i < searchDirs.length; i += 1) { 
        await searchDirs[i].delete(); 
      }  
    

    Returns Promise<number>

    Response status.

fetch

getChildren

  • The method gets all child directories.

      // Example of getting all filed from child directories 
       const children = await someDirectory.getChildren(); 
      let  allFilesInAllDirs :FileItem[]; 
      parents.forEach(dir => { 
        let files  = dir.getFiles(); 
            files.forEach(file =>{ 
                 allFilesInAllDirs.push(file); 
            }) 
      }); 
    

    Returns Promise<DirectoryItem[]>

    An array of child directory objects.

getChildrens

  • Deprecated. The method returns all child directories.

      // Example of getting all filed from child directories 
       const children = await someDirectory.getChildrens(); 
      let  allFilesInAllDirs :FileItem[]; 
      parents.forEach(dir => { 
        let files  = dir.getFiles(); 
            files.forEach(file =>{ 
                 allFilesInAllDirs.push(file); 
            }) 
      }); 
    
    deprecated

    The method is deprecated. Avoid using it.

    Returns Promise<DirectoryItem[]>

    An array of child directory objects.

getDirs

  • The method gets folders from the first-level nested directory.

      //example of getting all files from child directories 
       const dirsInDir = await someDirectory.getDirs(); 
      let allFilesInAllDirs  :FileItem[]; 
      dirsInDir.forEach(dir => { 
        let files = dir.getFiles();  
            files.forEach(file =>{ 
                allFilesInAllDirs.push(file);  
            }) 
      }); 
    

    Returns Promise<DirectoryItem[]>

    An array of directory objects.

getFiles

  • The method returns files from a directory.

      //Example of getting links to files in a directory 
       const filesInDir = await someDirectory.getFiles(); 
      filesInDir.forEach( file => file.getDownloadUrl()); 
    

    Returns Promise<FileItem[]>

    An array of file objects from a directory.

getParents

  • The method returns the directory’s parent directories sorted according to the nesting order.

      //Example of forming a path to a directory based on the  obtained data about the parent directories 
      const parents = await  someDirectory.getParents(); 
      let pathDir string = '/'; 
      parents. forEach(dir => { 
        pathDir = pathDir + dir.data.__name + '/' 
      }); 
    

    Returns Promise<DirectoryItem[]>

    An array of parent directory objects.

getPermissions

  • The method returns permissions for a folder.

    After successfully executing the request for permissions, you will receive a TPermissions object in the response. The received object can be modified or analyzed for various access checks.

    const  searchDir = await System.directories.search().
             where(di => di.__id. eq('<some id>')). 
             first(); 
    const perm = await searchDir. getPermissions(); 
    

    Returns Promise<TPermissions>

hasPermission

  • hasPermission(orgunit: TPermissionOrgunit, type: PermissionType): Promise<boolean>
  • The method checks access permissions PermissionType.

    The method allows for easy verification of the ability to perform the PermissionType operation with a folder. The method returns a flag indicating the result. If the flag value is true, the user can perform the requested operation with the folder. It is also possible to check access for org structure items.

    const user = Context.data. __createdBy;
    const searchDir = await System.directories.search(). 
              where(di => di.__id.eq('<some id>')). 
             first(); 
    const canUpdate =  await directory.hasPermission(user, PermissionType.DELETE); 
    if (canUpdate) {  
        await searchDir.delete(); 
    } 
    

    Parameters

    • orgunit: TPermissionOrgunit

      The group or user whose permissions are checked.

    • type: PermissionType

      Operation type.

    Returns Promise<boolean>

normalize

  • normalize(): void
  • Delete duplicate data in arrays.

    The method deletes duplicates in fields that store arrays of links to system objects (users, files, app items, or documents). For example, you can call this method after bulk editing data within an object.

    const  app1 = await Context.data.app1.fetch();
    const app2 = await Context.data.app2 .fetch(); 
    app1.data.executors.push(app2.data.executors); 
    app1.normalize();  
    // Now we need to go over the elements in the new array 
    app1.data.executors .forEach( ... ); 
    

    Returns void

setPermissions

  • The method sets access permissions for a folder.

    Use this method to modify access rights to a folder: add or remove access rights for a user, group, or org chart item. To add new access rights, use the TPermissionValue object, and to grant rights for specific operations, use PermissionType. After creating a new TPermissions object , you need to use this method to save the new access rights.

    const searchDir = await System.directories.search().
              where(di => di.__id.eq('<some id>')). 
             first(); 
    const user =  searchDir.data.__createdBy; 
    const permissions = new Permissions([ 
     new  PermissionValue(user, [PermissionType.DELETE, PermissionType.READ]), 
    ]);  
    await directory.setPermissions(perms); 
    

    Parameters

    Returns Promise<void>