StainlessS
17th January 2020, 03:26
This may or may not be a useful utility, posted as I would have found it of use. [Is real tedious to view 10,000 text files in a Notepad style app]
# ShowTextFiles.avs
/*
Req RT_Stats, v1.43+, Grunt.
Scan directory of text files, showing first few lines of each file on frame [original intent to aid recovery of accidentally deleted text files from 10,000 possible recovered txt files].
Outputs list of Files with SearchWord found to DebugView, even when DEBUG=False
*/
DIR = ".\recup_dir.1" # Directory to scan, or if DO_FSEL then Initial directory in File Selector
WildCard="*.txt" # Pipe Separated Wildcards, eg "*.txt|*.csv"
W=1024 # Frame Width
H=720 # Frame Height, 1st ((Height/20)-2) lines are shown on frame, top 2 lines show filename and Searchword Found frame when activated.
FPS=100.0 # Returned clip FPS, suggest 2.0 if not using SearchWord, or 100.0 if known Searchword present.
DO_FSEL = False # Use FileSelector if true, best use VDub2. [DONT use in AvsPMod, although might now be fixed, dont know]
SEARCHWORD="Galaxy Note" # If eg SearchWord contained in first ((Height/20)-2) Lines then will hi-lite shown text in YELLOW ("" = no search) Best use VDub2 if searchword.
FULLSEARCH=True # If true, search entire file, not just the visible lines shown on frame.
DEBUG=False # Debug info to DebugView (Google)
##################
myName="ShowTextFiles: "
Global Found = -1 # Searchword most recent found frame number.
Global FoundCnt=0 # Count of searchWord finds
FPS=FPS.Float
DIR = RT_GetFullPathName(DIR)
DIR = (DO_FSEL) ? RT_FSelFolder("Select Directory to scan for files",dir=DIR,Debug=true) : DIR
(DEBUG) ? RT_DebugF("Directory=%s",String(DIR),name=myName) : NOP
Assert(!DIR.IsInt || DIR!=0, "RT_FSelFolder: User Cancelled Directory Select") # User Cancelled
Assert(!DIR.IsInt, "RT_FSelFolder: Error="+String(DIR)) # Some other error
TEMP = RT_GetSystemEnv("TEMP")
TempList=TEMP + "\~" + RT_LocalTimeString + ".tmp"
(DEBUG) ? RT_DebugF("TempList=%s",TempList,name=myName) : NOP
FileCnt = RT_WriteFileList(DIR + "\" + WildCard,TempList) # Text files found
(DEBUG) ? RT_DebugF("FileCnt=%d",Filecnt,name=myName) : NOP
Assert(FileCnt>=0, "RT_WriteFileList: Error writing file list")
Assert(FileCnt>0, "RT_WriteFileList: No Files found")
BlankClip(Length=FileCnt,Width=W,Height=H,fps=FPS)
ARGS="TempList,SearchWord,FullSearch,Debug"
SSS = "ShowTextOnFrameFn(" + ARGS + ")"
Last.ScriptClip(SSS,args=ARGS,Local=True) # Req Grunt
Return last
Function ShowTextOnFrameFn(clip c,String TempList,string SearchWord,Bool FullSearch, Bool Debug) {
c
myName="ShowTextOnFrameFn: "
n=current_frame
DoSearch=SearchWord!=""
LinesMax = Height/20 # Max lines of text from file, to show on frame.
(DEBUG) ? RT_DebugF("%d] TemplList=%s LinesMax=%d",n,TempList,LinesMax,name=myName) : NOP
Fullname = RT_ReadTxtFromFile(TempList,Lines=1,Start=n).RT_TxtGetLine # Get line with text filename and strip n/l
Node = FullName.RT_FilenameSplit(12) # Name node + Extension
(DEBUG) ? RT_DebugF("Node=%s",Node,name=myName) : NOP
Lines = RT_FileQueryLines(FullName) # Lines of text in target text file
(DEBUG) ? RT_DebugF("Lines=%d",Lines,name=myName) : NOP
GetLines = Max(Min(LinesMax-2 , Lines),0) # Limited number of lines to read
(DEBUG) ? RT_DebugF("GetLines=%d",GetLines,name=myName) : NOP
Sometext = (GetLines>0)?RT_ReadTxtFromFile(FullName,Lines=GetLines,Start=0):"" # Read first few lines of text file
(DEBUG) ? RT_DebugF("SomeText=%s",SomeText,name=myName) : NOP
ShortFound = (DoSearch && !FullSearch) ? (RT_FindStr(Sometext,SearchWord,Sig=False,Pos=1)>0) : false # RT_FindStr returns 0 on Not Found.
Longfound = (DoSearch && FullSearch && Lines>0) ? (RT_FileFindStr(FullName,SearchWord,Sig=False,Pos=1,Start=0,Lines=Lines)>=0) : false # RT_FileFindStr returns line number [0 is possible line number]
IsFound=(ShortFound || LongFound)
(DEBUG) ? RT_DebugF("ShortFound=%s LongFound=%s SomeText='%s'",ShortFound,LongFound,SomeText,name=myName) : NOP
Global FoundCnt = (IsFound) ? FoundCnt+1 : FoundCnt # Update FoundCnt
Global Found = (IsFound) ? n : Found # Update to most recent found position
(IsFound) ? RT_DebugF("%d/%d] Foundcnt=%d %s\n%s\n**************************************************\n",n,Framecount-1,FoundCnt,Node,SomeText) : NOP
return (Found<0)
\ ? RT_Subtitle("%d/%d] \a!%s\a-\n\n%s",n,Framecount-1,Node,SomeText)
\ : RT_Subtitle("%d/%d] \a!%s \a6%d SEARCHWORDS FOUND, Latest @ %d\a%c\n\n%s",n,Framecount-1,Node,FoundCnt,Found,(Found==n)?RT_Ord("6"):RT_Ord("-"),SomeText)
}
EDITED:
SearchWord Found
https://i.postimg.cc/5X0Mc4f0/Show-Text-Files-00-00.jpg (https://postimg.cc/5X0Mc4f0)
EDIT: Should be Avs v2.58 compatible.
EDIT: I've managed to find 2 of the 3 missing files, so far, 19 more directories of files to scan [already manually deleted many files that were way too large, 9000+ files to go].
EDIT: Added, Outputs list of Files with SearchWord found to DebugView, even when DEBUG=False
Shows current Found Count. and latest Found frame, to both Frame, and DebugView.
If you are sure search word will be found, can bump up the FPS to 100.0 or so, and watch clip or output of DebugView.
EDIT: Added, FULLSEARCH to config.
Dont look like I'm gonna find the 3rd missing file (cant remember what was in it).
EDIT: Recovered files were recovered using PhotoRec [part of TestDisk recovery package], Photorec scans the recovered txt files to ascertain that they contain only text, not binary,
and gives them a generated filename [where not known] and a .txt extension.
TestDisk:- https://www.cgsecurity.org/wiki/TestDisk
PhotoRec:- https://www.cgsecurity.org/wiki/PhotoRec
TestDisk on wikipedia:- https://en.wikipedia.org/wiki/TestDisk
PhotoRec on wikipedia:- https://en.wikipedia.org/wiki/PhotoRec
# ShowTextFiles.avs
/*
Req RT_Stats, v1.43+, Grunt.
Scan directory of text files, showing first few lines of each file on frame [original intent to aid recovery of accidentally deleted text files from 10,000 possible recovered txt files].
Outputs list of Files with SearchWord found to DebugView, even when DEBUG=False
*/
DIR = ".\recup_dir.1" # Directory to scan, or if DO_FSEL then Initial directory in File Selector
WildCard="*.txt" # Pipe Separated Wildcards, eg "*.txt|*.csv"
W=1024 # Frame Width
H=720 # Frame Height, 1st ((Height/20)-2) lines are shown on frame, top 2 lines show filename and Searchword Found frame when activated.
FPS=100.0 # Returned clip FPS, suggest 2.0 if not using SearchWord, or 100.0 if known Searchword present.
DO_FSEL = False # Use FileSelector if true, best use VDub2. [DONT use in AvsPMod, although might now be fixed, dont know]
SEARCHWORD="Galaxy Note" # If eg SearchWord contained in first ((Height/20)-2) Lines then will hi-lite shown text in YELLOW ("" = no search) Best use VDub2 if searchword.
FULLSEARCH=True # If true, search entire file, not just the visible lines shown on frame.
DEBUG=False # Debug info to DebugView (Google)
##################
myName="ShowTextFiles: "
Global Found = -1 # Searchword most recent found frame number.
Global FoundCnt=0 # Count of searchWord finds
FPS=FPS.Float
DIR = RT_GetFullPathName(DIR)
DIR = (DO_FSEL) ? RT_FSelFolder("Select Directory to scan for files",dir=DIR,Debug=true) : DIR
(DEBUG) ? RT_DebugF("Directory=%s",String(DIR),name=myName) : NOP
Assert(!DIR.IsInt || DIR!=0, "RT_FSelFolder: User Cancelled Directory Select") # User Cancelled
Assert(!DIR.IsInt, "RT_FSelFolder: Error="+String(DIR)) # Some other error
TEMP = RT_GetSystemEnv("TEMP")
TempList=TEMP + "\~" + RT_LocalTimeString + ".tmp"
(DEBUG) ? RT_DebugF("TempList=%s",TempList,name=myName) : NOP
FileCnt = RT_WriteFileList(DIR + "\" + WildCard,TempList) # Text files found
(DEBUG) ? RT_DebugF("FileCnt=%d",Filecnt,name=myName) : NOP
Assert(FileCnt>=0, "RT_WriteFileList: Error writing file list")
Assert(FileCnt>0, "RT_WriteFileList: No Files found")
BlankClip(Length=FileCnt,Width=W,Height=H,fps=FPS)
ARGS="TempList,SearchWord,FullSearch,Debug"
SSS = "ShowTextOnFrameFn(" + ARGS + ")"
Last.ScriptClip(SSS,args=ARGS,Local=True) # Req Grunt
Return last
Function ShowTextOnFrameFn(clip c,String TempList,string SearchWord,Bool FullSearch, Bool Debug) {
c
myName="ShowTextOnFrameFn: "
n=current_frame
DoSearch=SearchWord!=""
LinesMax = Height/20 # Max lines of text from file, to show on frame.
(DEBUG) ? RT_DebugF("%d] TemplList=%s LinesMax=%d",n,TempList,LinesMax,name=myName) : NOP
Fullname = RT_ReadTxtFromFile(TempList,Lines=1,Start=n).RT_TxtGetLine # Get line with text filename and strip n/l
Node = FullName.RT_FilenameSplit(12) # Name node + Extension
(DEBUG) ? RT_DebugF("Node=%s",Node,name=myName) : NOP
Lines = RT_FileQueryLines(FullName) # Lines of text in target text file
(DEBUG) ? RT_DebugF("Lines=%d",Lines,name=myName) : NOP
GetLines = Max(Min(LinesMax-2 , Lines),0) # Limited number of lines to read
(DEBUG) ? RT_DebugF("GetLines=%d",GetLines,name=myName) : NOP
Sometext = (GetLines>0)?RT_ReadTxtFromFile(FullName,Lines=GetLines,Start=0):"" # Read first few lines of text file
(DEBUG) ? RT_DebugF("SomeText=%s",SomeText,name=myName) : NOP
ShortFound = (DoSearch && !FullSearch) ? (RT_FindStr(Sometext,SearchWord,Sig=False,Pos=1)>0) : false # RT_FindStr returns 0 on Not Found.
Longfound = (DoSearch && FullSearch && Lines>0) ? (RT_FileFindStr(FullName,SearchWord,Sig=False,Pos=1,Start=0,Lines=Lines)>=0) : false # RT_FileFindStr returns line number [0 is possible line number]
IsFound=(ShortFound || LongFound)
(DEBUG) ? RT_DebugF("ShortFound=%s LongFound=%s SomeText='%s'",ShortFound,LongFound,SomeText,name=myName) : NOP
Global FoundCnt = (IsFound) ? FoundCnt+1 : FoundCnt # Update FoundCnt
Global Found = (IsFound) ? n : Found # Update to most recent found position
(IsFound) ? RT_DebugF("%d/%d] Foundcnt=%d %s\n%s\n**************************************************\n",n,Framecount-1,FoundCnt,Node,SomeText) : NOP
return (Found<0)
\ ? RT_Subtitle("%d/%d] \a!%s\a-\n\n%s",n,Framecount-1,Node,SomeText)
\ : RT_Subtitle("%d/%d] \a!%s \a6%d SEARCHWORDS FOUND, Latest @ %d\a%c\n\n%s",n,Framecount-1,Node,FoundCnt,Found,(Found==n)?RT_Ord("6"):RT_Ord("-"),SomeText)
}
EDITED:
SearchWord Found
https://i.postimg.cc/5X0Mc4f0/Show-Text-Files-00-00.jpg (https://postimg.cc/5X0Mc4f0)
EDIT: Should be Avs v2.58 compatible.
EDIT: I've managed to find 2 of the 3 missing files, so far, 19 more directories of files to scan [already manually deleted many files that were way too large, 9000+ files to go].
EDIT: Added, Outputs list of Files with SearchWord found to DebugView, even when DEBUG=False
Shows current Found Count. and latest Found frame, to both Frame, and DebugView.
If you are sure search word will be found, can bump up the FPS to 100.0 or so, and watch clip or output of DebugView.
EDIT: Added, FULLSEARCH to config.
Dont look like I'm gonna find the 3rd missing file (cant remember what was in it).
EDIT: Recovered files were recovered using PhotoRec [part of TestDisk recovery package], Photorec scans the recovered txt files to ascertain that they contain only text, not binary,
and gives them a generated filename [where not known] and a .txt extension.
TestDisk:- https://www.cgsecurity.org/wiki/TestDisk
PhotoRec:- https://www.cgsecurity.org/wiki/PhotoRec
TestDisk on wikipedia:- https://en.wikipedia.org/wiki/TestDisk
PhotoRec on wikipedia:- https://en.wikipedia.org/wiki/PhotoRec