Skip to content

Commit efe2e94

Browse files
committed
MAVExplorer: support wildcards in 'file' command
"file *.lua" extracts all matching files to the current directory. An optional second argument specifies the destination directory.
1 parent e125839 commit efe2e94

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

MAVProxy/tools/MAVExplorer.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,18 @@ def cmd_file(args):
11771177
print("%s (length %u)" % (n, len(files[n])))
11781178
return
11791179
fname = args[0]
1180+
if any(c in fname for c in '*?['):
1181+
# wildcard: extract all matching files to a directory (default cwd)
1182+
matches = sorted(n for n in files if fnmatch.fnmatch(n, fname))
1183+
if not matches:
1184+
print("No files match %s" % fname)
1185+
return
1186+
destdir = args[1] if len(args) > 1 else '.'
1187+
for n in matches:
1188+
dest = os.path.join(destdir, os.path.basename(n))
1189+
open(dest, "wb").write(files[n])
1190+
print("Saved %s to %s" % (n, dest))
1191+
return
11801192
if not fname in files:
11811193
print("File %s not found" % fname)
11821194
return

0 commit comments

Comments
 (0)