Route

Move all the text files in a directory into subdirectories by name

#!/usr/bin/env python3
from pathlib import Path
import shutil

for f in Path(".").glob("*.txt"):
    if f.name[0] in "abcdefghijklmnopqrstuvwxyz":
        d = Path(f.name[0])
        if d.is_dir():
            shutil.move(str(f), str(d / f.name))

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply