File
interface cAlgo.API Since 5.7
DesktopCLICloud
Represents a file.
Environment behaviour
Cloud — not supported. Exists returns false; reads return empty string/array; writes and appends silently do nothing. No exception.
Definition
public interface File
Namespace: cAlgo.API · Group: Utility
Remarks
You can use this as a parameter type to get direct read and write access to a file.
Examples
public partial class FileSample : Robot
{
protected override void OnStart()
{
if (!TradesLog.Exists())
TradesLog.WriteAllText("Time,Symbol,Side" + Environment.NewLine);
Positions.Opened += args => TradesLog.AppendAllText($"{Server.Time:O},{args.Position.SymbolName},{args.Position.TradeType}{Environment.NewLine}");
Print("Logging trades to {0} ({1} bytes)", TradesLog.Name, TradesLog.Size);
}
}
def on_start(self):
if not api.TradesLog.Exists():
api.TradesLog.WriteAllText("Time,Symbol,Side\n")
api.Positions.Opened += self.on_position_opened
api.Print(f"Logging trades to {api.TradesLog.Name} ({api.TradesLog.Size} bytes)")
def on_position_opened(self, args):
position = args.Position
api.TradesLog.AppendAllText(f"{api.Server.Time},{position.SymbolName},{position.TradeType}\n")
{
"AccessRights": "None",
"Parameters": [
{
"Name": "TradesLog",
"DisplayName": "Trades Log",
"Type": "File"
}
]
}
Methods
| Name | Description |
|---|---|
AppendAllLines 2 overloadsDesktopCLICloudvoid | Appends lines to file. |
AppendAllText 2 overloadsDesktopCLICloudvoid | Append text to file. |
ExistsDesktopCLICloudbool | Returns True if File exists otherwise False. |
ReadAllBytesDesktopCLICloudbyte[] | Reads the contents of the file into a byte array. |
ReadAllText 2 overloadsDesktopCLICloudstring | Reads all the text in the file. |
ReadBytesDesktopCLICloudbyte[] | Reads a sequence of bytes from the file. |
ReadLines 2 overloadsDesktopCLICloudstring[] | Reads the lines of file. |
WriteAllBytesDesktopCLICloudvoid | Overwrites file content with passed bytes. |
WriteAllText 2 overloadsDesktopCLICloudvoid | Overwrites file content with passed text content. |
WriteBytesDesktopCLICloudvoid | Writes a chunk of data to file specific position. |
Properties
| Name | Description |
|---|---|
CreationTimeDesktopCLICloudDateTime | Gets the creation time of the file. |
ExtensionDesktopCLICloudstring | Gets the extension part of the file name, including the leading dot '.' even if it is the entire file name, or an empty string if no extension is present. |
LastAccessTimeDesktopCLICloudDateTime | Gets the time the current file was last accessed. |
LastWriteTimeDesktopCLICloudDateTime | Gets the time when the current file was last written to. |
NameDesktopCLICloudstring | Gets file name without path. |
SizeDesktopCLICloudlong | Gets file size in bytes. |