From 075d46f93f2c9ae0f228b9b28766f2d017e2781e Mon Sep 17 00:00:00 2001 From: Marvin <43289257+MarvinZhong@users.noreply.github.com> Date: Fri, 15 Apr 2022 10:53:07 +0800 Subject: [PATCH] Create dupeFiles.py modify files with the same name that have different extensions --- dupeFiles.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 dupeFiles.py diff --git a/dupeFiles.py b/dupeFiles.py new file mode 100644 index 0000000..81f10a2 --- /dev/null +++ b/dupeFiles.py @@ -0,0 +1,21 @@ +# modify files with the same name that have different extensions +import os + +folderPath = 'C:/Users/Folders' + + +def main(): + for filename in os.listdir(folderPath): + # get filename with json ext + if filename.endswith('.json'): + # get filename with png ext + if filename.replace('.json', '.png') in os.listdir(folderPath): + # remove both + print(filename) + os.remove(os.path.join(folderPath, filename)) + os.remove(os.path.join(folderPath, filename.replace('.json', '.png'))) + + +# Driver Code +if __name__ == '__main__': + main()