file Demonstrates file operations

file.py

With the addition of an SD card to the system, file operations become useful. This module provides examples of file operations on the SD card.

Notes

  • “SD/” is the root folder for the SD drive. “SD/TX1” is an example subfolder
  • Use forward slash / to separate folders and files e.g. “SD/folder/file.txt”
  • FAT32 is the only supported file system
  • The system automatically mounts the SD card
  • The command line interface supports advanced file operations (please see user manual)
  • Files may be transmitted to an FTP server (please see user manual)
  • The “SD/TX1”, “SD/TX2”, etc. folders are used to hold files for transmissions
  • Transmitted files are automatically deleted

MicroPython

  • MicroPython file operations have some minor differences from Python 3.5
  • include uos to use file operations
  • use uos.exists() to see if a file exists (there is no uos.path module)
  • seek is limited to files under 1GB
file.diagnostic_file_for_tx()

Creates a diagnostic file and places into the TX1 folder

file.file_demo()
Returns:
Return type:
file.format_date(time_t)

returns a string with the formatted date as YYYY_MM_DD_HH_MM_SS

file.unique_file_name(prefix, time_t, ext)

Creates a unique file name using this pattern: prefix_YYYY_MM_DD_HH_MM_SS.ext if such a file already exists, appends _xN to file name above, where N is an incrementing number, until a unique file name is found

Returns:unique file name
Return type:str