Python Forum

Full Version: how to view file content of .docx while in Recycling bin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
# trying to search Documents or Recycling bin folders on Windows 10 for a file entered by user input .docx.
#It needs to be be searched by file content string  The file contains one word "docxfile" and needs to be identified by its content while in recycling bin prior to being restored...At present I can view filename and restore to read content...i'm hoping to find how to view the content prior to restoring
import os, sys
import fnmatch
import winshell
import docx

def file_name():
	home = os.path.expanduser('~')
	filename = input('Search For?: ')
	directory_check(home, filename)

def rec_bin(filename):
	for item in winshell.recycle_bin():
		if fnmatch.fnmatch(os.path.basename(item.original_filename()), filename):
			item.undelete()
			print('File restored.')
			string_check(filename)
		

def string_check(filename):
	with open(filename, 'r') as f:
		searchfile = open(filename, 'r')
		for line in searchfile:
			if 'docxfile' in line:
				print('Found string: ', line)
			else:
				print('No files found')

def directory_check(home, filename):
	folder = os.path.join(home, 'Documents')
	fileexists = os.path.isfile(filename)
	if fileexists is True:
		print(folder)
		print("File exists.")
		string_check(filename)
	else:
		print('File not found. looking in recycling bin...')
		
		rec_bin(filename)

file_name()