The object is used to work with file directories. It allows you to perform operations with directories stored on the disk: searching for directories, getting directories inside a directory, obtaining parent or child directories of different levels, creating new directories or deleting existing ones, and getting files from a directory.

Hierarchy

  • Directories

Methods

create

  • The method creates a new directory.

    // Example of creating a new directory 
    const name = 'Name of  the new directory'; 
    const parentId = '8c110182-b022-5f31-ac3d-290fdc1d4fe1';  
    const newDirectory = await System.directories.create(directoryData); 
    

    Parameters

    • name: string
    • parentId: string

    Returns Promise<DirectoryItem>

    Directory object.

delete

  • delete(directoryId: string): Promise<number>
  • The method deletes a directory by ID.

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

    Parameters

    • directoryId: string

      ID of the directory.

    Returns Promise<number>

    Response status.

getChildren

  • The method gets all child directories.

      // Example of deleting all child directories 
      const  childsDir = await System.directories.getChildrens(idDir); 
      childsDir. forEach(async dir => await dir.delete()); // Deleting all child directories  
    

    Parameters

    • directoryId: string

      ID of the directory.

    Returns Promise<DirectoryItem[]>

    An array of child directory objects.

getChildrens

  • Deprecated. The method returns all child directories.

      // Example of deleting all child directories. 
      const  childsDir = await System.directories.getChildrens(idDir); 
      childsDir. forEach(async dir => await dir.delete()); // Deleting all child directories  
    
    deprecated

    The method is deprecated. Avoid using it.

    Parameters

    • directoryId: string

      ID of the directory.

    Returns Promise<DirectoryItem[]>

    An array of child directory objects.

getDirs

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

      // Let’s get all files from child directories 
      const  dirsInDir = await System.directories.getDirs(idDir); 
      let  allFilesInAllDirs :FileItem[]; 
      dirsInDir.forEach(dir => { 
        let  files = dir.getFiles(); 
            files.forEach(file =>{ 
                 allFilesInAllDirs.push(file); 
            }) 
      }); 
    

    Parameters

    • directoryId: string

      ID of the directory.

    Returns Promise<DirectoryItem[]>

    An array of directory objects from the specified directory.

getFiles

  • getFiles(directoryId: string): Promise<FileItem[]>
  • The method returns files from a directory.

       //Example of getting links to files in a directory. 
        const idDir = '8c110182-b022-5f31-ac3d-290fdc1d4fe1' 
      const filesInDir =  await System.directories.getFiles(idDir); 
      filesInDir.forEach(file => file .getDownloadUrl()); 
    

    Parameters

    • directoryId: string

      ID of the directory.

    Returns Promise<FileItem[]>

    An array of file objects from a directory.

getParents

  • The method gets a directory’s parent directories.

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

    Parameters

    • directoryId: string

      ID of the directory.

    Returns Promise<DirectoryItem[]>

    An array of parent directory objects.

search

  • The method conducts search for directories stored on the disk.

    You can use this method to:

    • Filter directories using different search parameters.
    • Search for and get a specific or the first item found in the query.
    • Sort search results.
    • Limit the number of search results or see search results on several pages.
       // Example of getting  directories created by the user (some user_id) 
       const position = await  System.directories.search().where(d => d.__createdBy.eq('<some id>')).all();  
      

    Returns DirectoriesSearch

    Object to create a directory search request.