0

I am trying to run the following command via my python script, to unzip a bunch of csv.gz files

os.system("find /upload/ -name '*.csv.gz' -print -exec gzip -d {} \") <- Syntax error : EOL while scanning string literal.

#When I try to escape it

os.system("find /upload/ -name '*.csv.gz' -print -exec gzip -d {} \\") <- find: missing parameter for « -exec »

How can I execute find /upload/ -name '*.csv.gz' -print -exec gzip -d {} \ via os.system?

Is there any alternative to os.system("find /upload/ -name '*.csv.gz' -print0 | xargs -0 -n1 gzip -d") I could use?

Imad
  • 1,627
  • 21
  • 33

2 Answers2

1

Not using a shell at all is actually a simplification here, as long as you understand what you are doing. You have to add the missing semicolon as already mentioned in the other answer.

import subprocess

subprocess.run([
    'find', '/upload/', '-name', '*.csv.gz', '-print',
    '-exec', 'gzip', '-d', '{}', ';'], check=True)

Maybe see also Running Bash commands in Python

tripleee
  • 158,107
  • 27
  • 234
  • 292
0

You need an (escaped) semicolon:

os.system("find /upload/ -name '*.csv.gz' -print -exec gzip -d {} \\;")

Toby Speight
  • 25,191
  • 47
  • 61
  • 93
Imad
  • 1,627
  • 21
  • 33