Sep-26-2022, 11:34 AM
(This post was last modified: Sep-26-2022, 12:14 PM by snippsat.
Edit Reason: Fix code tag
)
Hi Team,
how to accept multiple values or a list of values from command prompt. and store into single variable.
folderpath, next list of file names to delete.
accept "ab,xy,py,cd,ef,gh" and store into single variable.
**python test.py "C:/Users/malle/OneDrive/Desktop/C/test_data" "ab,xy,py,cd,ef,gh"**
how to accept multiple values or a list of values from command prompt. and store into single variable.
folderpath, next list of file names to delete.
accept "ab,xy,py,cd,ef,gh" and store into single variable.
**python test.py "C:/Users/malle/OneDrive/Desktop/C/test_data" "ab,xy,py,cd,ef,gh"**
from pathlib import Path import sys def remove_files(folderpath, files): import os os.chdir(folderpath) collection = [] collection = files.split(",") for coll in collection: files = Path.cwd().glob(f"*{coll}*") for file in files: file.unlink(missing_ok=True) if __name__ == "__main__": pattern = "ab,xy,py,cd,ef,gh" root = "C:/Users/malle/OneDrive/Desktop/C/test_data" remove_files(root, pattern)