Created
June 8, 2022 07:05
-
-
Save m3hransh/d02f0458ec9f780639cf6cff54fd509e to your computer and use it in GitHub Desktop.
Useful python scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
moving files base on the text content | |
''' | |
from os import scandir | |
from os.path import isfile, join | |
import shutil | |
mypath = './obsidian' | |
dstpath = './German/Notes/' | |
content = '[[German]]' | |
# moving all files that has '[[German]]' in them to dst directory | |
with scandir(mypath) as entries: | |
for entry in entries: | |
if entry.is_file(): | |
with open(join(mypath, entry.name), 'r') as f: | |
if content in f.read(): | |
src = join(mypath, entry.name) | |
dst = join(dstpath, entry.name) | |
print(f'mv {src} -> {dst}') | |
shutil.move(src, dst) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment