0

I am fairly new to python and working on a little project for personal use.

I need to create a dummy placeholder file in all empty directories

I did almost everything except the command to create the file, because I do not know how.

my code:

import os, glob

dirs = []
paths = ["system", "vendor"]
for path in paths:
    dirs.append(glob.glob(path + '/**/', recursive=True))

for dir in dirs:
    for dir1 in dir:
        if len(os.listdir(dir1)) == 0:
            // how would i create a placeholder file
        else: continue

Thank you

John Bielowski
  • 199
  • 2
  • 11
  • [pathlib's touch](https://docs.python.org/3/library/pathlib.html#pathlib.Path.touch) maybe? – Hampus Larsson Jun 01 '20 at 13:41
  • @HampusLarsson thank you for your answer, but is there a way to do it without importing anything – John Bielowski Jun 01 '20 at 13:42
  • If your requirements are to not include the Python Standard Library, then please include that very important statement in the question. Also, as a side-note, you're already importing modules `os` and `glob` in your sample-code! – Hampus Larsson Jun 01 '20 at 13:43
  • its not, but would be better to not have them. I asked if its possible. – John Bielowski Jun 01 '20 at 13:44
  • 1
    Why would it be better? It’s not that you would have to install anything, they are part of any Python installation, that’s why it’s called the "standard library". – mkrieger1 Jun 01 '20 at 13:48
  • "is there a way to do it without importing anything?" Yes, it's possible, because someone already has done it with Python-code, or python-executable code, because it's in the standard library. – Hampus Larsson Jun 01 '20 at 13:48
  • alright how would i do it with pathlib.touch – John Bielowski Jun 01 '20 at 13:49
  • 1
    Does this answer your question? [Create empty file using python](https://stackoverflow.com/questions/12654772/create-empty-file-using-python) – mkrieger1 Jun 01 '20 at 13:50

0 Answers0