Skip to content

Instantly share code, notes, and snippets.

@m3hransh
Created June 8, 2022 07:05
Show Gist options
  • Save m3hransh/d02f0458ec9f780639cf6cff54fd509e to your computer and use it in GitHub Desktop.
Save m3hransh/d02f0458ec9f780639cf6cff54fd509e to your computer and use it in GitHub Desktop.
Useful python scripts
'''
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