-2

I want to create script that creates folder with name from the user Thank you this is my script

#!/bin/python3
import os
folder = str(input())
createFolder = 'mkdir' folder
os.system(createFolder)
David Buck
  • 3,752
  • 35
  • 31
  • 35
Who123
  • 29
  • 5
  • 1
    Welcome to StackOverflow. Could you please read [How to Ask a Question](https://stackoverflow.com/help/how-to-ask) to help you improve the level of detail in your question. – David Buck Nov 02 '19 at 20:38
  • Possible duplicate of [How to create new folder?](https://stackoverflow.com/questions/1274405/how-to-create-new-folder) – azro Nov 02 '19 at 20:56

1 Answers1

0

If you ran the code, you will notice you receive the following error:

File "/Users/felipefaria/Desktop/test/main.py", line 3
    createFolder = 'mkdir' folder
                                ^
SyntaxError: invalid syntax

Simply formatting your code properly will make it work:

import os

folder = str(input())
createFolder = "mkdir " + folder
os.system(createFolder)

Notice the space after mkdir so that is is mkdir {name} as oppose to mkdir{name}.

felipe
  • 7,324
  • 2
  • 28
  • 37
  • Felice Faria thank you very much for the answer . I have one more question what is the difference from import subprocess and import os for linux commands – Who123 Nov 03 '19 at 21:26
  • In essence, [`subprocess` is a newer module that can be used to replace `os.system` and `os.spawn`](https://docs.python.org/3/library/subprocess.html#module-subprocess): "This module intends to replace several older modules and functions." – felipe Nov 04 '19 at 17:23