---
title: "Files & folders"
canonical: "https://docs.cuesystem.com/space/CVCHELP/512983041/Files%20%26%20folders"
format: markdown
---
> Macro (toc)

---

# Names of files and folders 

The names of files and folders are case sensitive (e.g. "MyData.txt" and "mydata.txt" are different files). 

The name must: 

- not be equivalent to "." (decimal point),
- not be equivalent to ".." (double decimal point),
- not be equivalent to any of the followed names case insensitive: "CON", "PRN", "AUX", "CLOCK$", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
- contain only characters with code from 32 to 126 except the followed characters:

|  |  |
| --- | --- |
| Character | Description |
| < | Less-Than Sign |
| > | Greater-Than Sign |
| : | Colon |
| " | Quotation Mark |
| / | Solidus, Slash |
| \ | Reverse Solidus, Backslash |
| | | Vertical Line |
| - | Asterisk |
| ? | Question Mark |

The path to the file must begin with the /filestorage. It must be lowercase. 

#### Syntax of the path to the file 

```
/filestorage/folder1name/folder2name/folderNname/filename
```

#### Example 

```visualbasic
/filestorage/logfile.txt 
/filestorage/mydatafile.cfg 
/filestorage/myfolder/myfile.cfg 
/filestorage/myfolder/mysubfolder/myfile.cfg
```

# CreateFolder 

This function creates a new folder.  

#### Syntax 

```visualbasic
Function CreateFolder(foldername As Text) As Boolean
```

#### Parameters 

foldername 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> The path name of the folder to be created. See <u>rules of names of files and folders</u>. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. 

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[108](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#108)</u>, <u>[109](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#109)</u>, <u>[204](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#204)</u>. 

# DeleteFolder 

This function deletes an existing folder and its content. 

### Syntax 

```visualbasic
Function DeleteFolder(foldername As Text) As Boolean
```

#### Parameters 

foldername 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the pathname of the folder to be deleted.  

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. 

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[108](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#108)</u>, <u>[109](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#109)</u>, <u>[203](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#203)</u>. 

# DeleteFile 

This function deletes an existing file. 

#### Syntax 

```visualbasic
Function DeleteFile(filepathname As Text) As Boolean
```

#### Parameters 

filepathname 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the pathname of the file to be deleted. See <u>rules of names of files and folders</u>. 

#### Return value* *

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. 

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[81](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#81)</u>, <u>[108](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#108)</u>, <u>[109](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#109)</u>, <u>[110](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#110)</u>. 

# **FileExists** 

This function returns True if the file exists otherwise returns False. 

#### Syntax 

```visualbasic
Function FileExists(filepathname As Text) As Boolean
```

#### Parameters 

filepathname 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the name of the file. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True if the file exists otherwise it is False. 

# FolderExists 

This function returns True if the folder exists otherwise returns False. 

#### Syntax 

```visualbasic
Function FolderExists(foldername As Text) As Boolean
```

#### Parameters 

foldername 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the name of the folder. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True if the folder exists otherwise it is False. 

# GetFolderContent 

This function searches a folder for direct children (files or subfolders) with names that matches a mask and flags 

#### Syntax 

```visualbasic
Function GetFolderContent(folderpathname As Text, ByRef content As Array[] As _FileFolderInfoStructure, ByRef validitems As Long, ByRef totalitems As Long, Optional mask As Text := "*", Optional fromindex As Long :=1, Optional flags As Long := _FILTER_FILES BitOr _SORT_BY_NAME) As Boolean
```

#### Parameters 

folderpathname 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the pathname of the folder. 

content 

It is destination array that receives information about found files and folders that matches a mask and flags. 

validitems 

It is count of valid items in the destination array content. 

totalitems 

It is count of all items matching the mask and flags in the folder. 

mask 

It is the name mask. The mask supports the asterisk character ( “*” ) matches zero or more characters and the question mark (“?”) matches exactly one character. The mask also supports character “|”** **which allows to insert more masks. 

Example masks: 

"*" – all 

"*.png"  - all items with extension png 

"*.png|*.jpg|*.jpeg"  - all items with extension png or jpg or jpeg 

fromindex 

This parameter determine from which index in sorted  

flags 

_FILTER_FILES – search for files only 

_FILTER_FOLDERS – search for folders only 

_SORT_DESCENDING – reverse order while sorting 

_SORT_BY_NAME – sort items by name 

_SORT_BY_SIZE  – sort items by size 

_SORT_BY_TIME_MODIFIED  – sort items by modification time 

**Structure _FileFolderInfoStructure** 

This structure contains information about a file or a folder.  

```
Global Structure _FileFolderInfoStructure  
  Var Path As Text[260] 
  Var Name As Text[260] 
  Var IsFile As Boolean 
  Var TimeModified As Time 
  Var Size As Long 
End Structure
```

Path

It is a full path without a file or a folder name with the slash at the end 

Name

It is a file or a folder name 

IsFile

It is True if it is a file or False otherwise. 

TimeModified

It is a last modified time. 

Size

It is value of the file size in bytes.  It is zero if it is a folder. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs.

The function <u>[GetLastError](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[108](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#108)</u>, <u>[109](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#109)</u>, <u>[205](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#205)</u>, <u>[207](/wiki/spaces/CVCHELP/pages/510525445/Command+errors#207)</u>. 

#### Example 

This example shows information about all files from the folder /filestorage, sorted by file name 

```visualbasic
Var dst[2] As _FileFolderInfoStructure 
Var validindst As Long 
Var totalcount As Long 
Var fromindex As Long 
Var i As Long 

DebugPrint("All files in the folder /filestorage, sorted by name") 
fromindex := 1 

Do While True 
  If GetFolderContent("/filestorage",dst,validindst,totalcount,"*",fromindex) = False Then 
    Exit Do 
  End If  

  fromindex += validindst 

  For i := 1 To validindst 
    DebugPrintFormat("{t} {n}",dst[i].Name,dst[i].Size) 
  End For 
End Do
```

#### Example 

This example show information about all files with extension **txt** from the folder /filestorage , sorted by file size 

```visualbasic
Var dst[2] As _FileFolderInfoStructure 
Var validindst As Long 
Var totalcount As Long 
Var fromindex As Long 
Var i As Long 

DebugPrint("All files with extension txt in the folder /filestorage, sorted by size") 
fromindex := 1 

Do While True 
  If GetFolderContent("/filestorage",dst,validindst,totalcount,"*.txt",fromindex, _FILTER_FILES BitOr _SORT_BY_SIZE) = False Then 
    Exit Do 
  End If  

  fromindex += validindst 

  For i := 1 To validindst 
    DebugPrintFormat("{t} {n}",dst[i].Name,dst[i].Size) 
  End For 
End Do
```

# MoveFile 

This function moves (renames) an existing file.  

#### Syntax 

```visualbasic
Function MoveFile(existingfilepathname As Text, newfilepathname  As Text, Optional failifexist As Boolean := False) As Boolean
```

#### Parameters 

existingfilepathname 

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the current name of the file. 

newfilepathname   

<u>[Text](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the new name for the file. 

failifexist 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> If this parameter is True and the new file specified by newfilepathname already exists, the functions return False. If this parameter is False and the new file specified by newfilepathname already exists, the function overwrites the existing file and returns True. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True if the file exists otherwise it is False.