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.

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