FEATHER-CHARGER-FICHIER-MICROPYTHON-FILEOP

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Opérations sur fichiers

In addition to running code ampy you can also manipulate files on a MicroPython board's filesystem. You can copy files from your computer to the board, read files from the board back to your computer, and even create and manage directories on the board.

Think of the filesystem on a MicroPython board like the filesystem on your computer. Just like on your computer your board can have a complex hierarchy of directories with files and other subdirectories inside them. MicroPython's filesystem is similar to Unix filesystems that separate parts of the path with forward slashes ('/') between parent directories. For example a file /foo/bar.txt on a MicroPython board exists in a folder foo under the root of the board.

Copier des fichiers sur la carte

The put command can copy files from your computer to a MicroPython board. This is great for copying over Python source code and other files you create on your computer.

For example to copy a file called test.py from your computer to the root of a MicroPython board's filesystem under /test.py run the following command:

ampy --port /serial/port put test.py

Where /serial/port is the path or name of the serial port connected to the MicroPython board. Make sure test.py is in the same directory as you're running the command too. If the file isn't there then specify the full path to it on your computer.

You can also put the file on the board in a path other than the root. Just specify as another argument the full path and filename to use on the board. For example to copy a test.py from your computer to a file /foo/bar.py on the board run (note the parent foo directory must already exist!):

ampy --port /serial/port put test.py /foo/bar.py

Lire des fichiers depuis la carte

The get command can read and copy files from a MicroPython board to your computer.

For example to print the contents of /boot.py from a board run the following command:

ampy --port /serial/port get boot.py

{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com

This will print out the contents of boot.py from the board's root directory.

You can instead copy the contents of boot.py into a file on your computer by specifying the path to the file to save as a second argument. For example to copy /boot.py from a board to a file board_boot.py on your computer you can run:

ampy --port /serial/port get boot.py board_boot.py

{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com

Créer des répertoire

You can create hierarchies of folders on the MicroPython board's filesystem with the mkdir command.

For example to create a /foo folder under the root of a board run the following command:

ampy --port /serial/port mkdir foo

You can create directories inside directories too, for example to create a folder bar inside the foo folder above you can run:

ampy --port /serial/port mkdir /foo/bar

Make sure the parent foo directory exists before trying to create the bar subdirectory inside of it! The mkdir command won't create parent directories that don't exist.

Lister les répertoires

You can list the file and folder contents of a directory with the ls command.

If you don't specify any argument to the ls command then the contents of the MicroPython board's root will be listed. However if you'd like to list the contents of a different directory just specify its path on the board as an argument.

For example to list the root contents of a board run:

ampy --port /serial/port ls

{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com

Or to list the contents of a subfolder foo run:

ampy --port /serial/port ls /foo

Effacer des fichiers et répertoires

The rm command can remove a file or directory from a MicroPython board's filesystem. To use the command just specify as an argument the path to the file or directory on the board to delete. Note that directories must be empty before they can be deleted!

For example to delete a file test.py in the root of a board run the following commmand:

ampy --port /serial/port rm test.py

Or to delete a folder /foo/bar, assuming it's empty, run the following command:

ampy --port /serial/port rm /foo/bar

Source: MicroPython Basics: Load Files & Run Code
Créé par Tony DiCola pour AdaFruit Industries.

Traduit par Meurisse D. pour MCHobby

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com