Python Forum
how to view file content of .docx while in Recycling bin
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to view file content of .docx while in Recycling bin
#1
# 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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  docx file to pandas dataframe/excel iitip92 1 2,389 Jun-27-2024, 05:28 AM
Last Post: Pedroski55
  no module named 'docx' when importing docx MaartenRo 1 5,319 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Replace a text/word in docx file using Python Devan 4 19,891 Oct-17-2023, 06:03 PM
Last Post: Devan
  Use module docx to get text from a file with a table Pedroski55 8 16,377 Aug-30-2022, 10:52 PM
Last Post: Pedroski55
  python-docx regex: replace any word in docx text Tmagpy 4 3,645 Jun-18-2022, 09:12 AM
Last Post: Tmagpy
  Extracting Specific Lines from text file based on content. jokerfmj 8 5,412 Mar-28-2022, 03:38 PM
Last Post: snippsat
Thumbs Up Parsing a YAML file without changing the string content..?, Flask - solved. SpongeB0B 2 3,053 Aug-05-2021, 08:02 AM
Last Post: SpongeB0B
  Rename docx file from tuple gjack 2 2,924 Oct-20-2020, 05:33 PM
Last Post: gjack
  Opening file and outputting its text content example leodavinci1990 1 2,437 Oct-12-2020, 05:33 AM
Last Post: buran
  Error while parsing tables from docx file aditi 1 5,148 Jul-14-2020, 09:24 PM
Last Post: aditi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020