Skip to content

Commit 263737e

Browse files
jimmodpgeorge
authored andcommitted
tools/pyboard.py: Add "touch" filesystem command.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent a311e9e commit 263737e

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

docs/reference/mpremote.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ The full list of supported commands are:
131131
- ``rm <src...>`` to remove files on the device
132132
- ``mkdir <dirs...>`` to create directories on the device
133133
- ``rmdir <dirs...>`` to remove directories on the device
134+
- ``touch <file..>`` to create the files (if they don't already exist)
134135

135136
- mount the local directory on the remote device:
136137

@@ -192,8 +193,8 @@ Shortcuts can be defined using the macro system. Built-in shortcuts are::
192193

193194
- ``c0``, ``c1``, ``c2``, ``c3``: connect to COM?
194195

195-
- ``cat``, ``ls``, ``cp``, ``rm``, ``mkdir``, ``rmdir``, ``df``: filesystem
196-
commands
196+
- ``cat``, ``ls``, ``cp``, ``rm``, ``mkdir``, ``rmdir``, ``touch``, ``df``:
197+
filesystem commands
197198

198199
- ``reset``: reset the device
199200

docs/reference/pyboard.py.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,13 @@ Filesystem access
9292

9393
Using the ``-f`` flag, the following filesystem operations are supported:
9494

95-
* ``cp src [src...] dest`` Copy files to/from the device.
9695
* ``cat path`` Print the contents of a file on the device.
96+
* ``cp src [src...] dest`` Copy files to/from the device.
9797
* ``ls [path]`` List contents of a directory (defaults to current working directory).
98-
* ``rm path`` Remove a file.
9998
* ``mkdir path`` Create a directory.
99+
* ``rm path`` Remove a file.
100100
* ``rmdir path`` Remove a directory.
101+
* ``touch path`` Create a file if it doesn't already exist.
101102

102103
The ``cp`` command uses a ``ssh``-like convention for referring to local and
103104
remote files. Any path starting with a ``:`` will be interpreted as on the

tools/pyboard.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ def fs_rmdir(self, dir):
543543
def fs_rm(self, src):
544544
self.exec_("import uos\nuos.remove('%s')" % src)
545545

546+
def fs_touch(self, src):
547+
self.exec_("f=open('%s','a')\nf.close()" % src)
548+
546549

547550
# in Python2 exec is a keyword so one must use "exec_"
548551
# but for Python3 we want to provide the nicer version "exec"
@@ -595,11 +598,12 @@ def fname_cp_dest(src, dest):
595598
op(src, dest2, progress_callback=progress_callback)
596599
else:
597600
op = {
598-
"ls": pyb.fs_ls,
599601
"cat": pyb.fs_cat,
602+
"ls": pyb.fs_ls,
600603
"mkdir": pyb.fs_mkdir,
601-
"rmdir": pyb.fs_rmdir,
602604
"rm": pyb.fs_rm,
605+
"rmdir": pyb.fs_rmdir,
606+
"touch": pyb.fs_touch,
603607
}[cmd]
604608
if cmd == "ls" and not args:
605609
args = [""]

0 commit comments

Comments
 (0)