So I want to be able to use a python script to copy the contents of a folder and then be able to paste those contents to a location of my choosing i.e. text file, browser, etc... I came across this solution for copying text to the clipboard, but when i implement this solution I am not able to paste anything. I am using python 3.4. Below is code i am using:
import os
import tkinter as tk
import tkinter.filedialog
r = tk.Tk()
r.withdraw()
photo_path= tkinter.filedialog.askdirectory(title='Which folder would you like to copy the contents from?', initialdir='/')
# Get list of filenames in current directory
file_list=[]
for filename in os.listdir(photo_path):
if os.path.splitext(filename)[1]=='.JPG':
file_list.append(os.path.splitext(filename)[0])
else: pass
file_search='code:('+' OR '.join(file_list)+')'
r.clipboard_clear()
r.clipboard_append(file_search)
r.destroy()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…