Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
![]() |
#1 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,878
|
ShowTextFiles.avs - Show textfiles on blank video
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]
Code:
# 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) } SearchWord Found ![]() 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
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 17th January 2020 at 10:09. |
![]() |
![]() |
![]() |
#2 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,878
|
Above scipt updated.
Found Bug in RT_stats v1.43 and latest RT_Stats v2 Beta, Code:
RT_FileFindStr(String FileName,string FndS,bool "Sig"=True,int "Pos"=1,int "Start"=0,int "Lines"=0) Finds unnamed string 'FndS' in 'FileName' text file, starting at line 'Start' and searching 'Lines' number of text lines. FileName: Name of a file containing text to search. FndS: is a string and will be considered terminated early at the first carriage return [Chr(13)] or newline [Chr(10)], carriage returns and newlines will not be findable using this function. Sig: Default=True, does case significant comparison, insignificant if false. Pos: Default=1, is the character start position in an individual line of text to start searching for the FndS string. Allows you to skip search on first Pos-1 characters within all lines of text. If Pos less than 1, then will return -ve number (usually -1), Not Found. Start: Default 0, is the 0 relative starting line where the searching begins in the text file. Lines: Default 0(all lines). Number of lines text to seach, starting at 'Start' line. A -ve return is 'Not Found'. On success returns the line number of the first instance of a found string in the Start and Lines range of lines. An empty "" FndS will always return -ve result, ie Not Found. see RT_FileQueryLines, to inquire number lines in a text file. see RT_ReadTxtFromFile to extract a range of lines from a text file. NOTE, Character position 'Pos' is 1 relative whereas multi-line line 'Start' index is 0 relative. Care must be taken if mixing RT_FindStr and RT_TxtFindStr or RT_FileFindStr, RT_FindStr returns 0 on error, the other two return -ve on error(0 denoting valid line zero). I have fixed the bug in the above script, and will update RT_Stats dll's soon. Script bugfix in Blue. Code:
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) } I have rarely used RT_FileFindStr() in existing scripts, maybe 2 or 3. EDIT: Recovered files were recovered using PhotoRec [part of TestDisk recovery package, selecting to recover only .txt files], 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. PhotoRec would likely not even try to recover 0 length files as they are likely not detected as txt files, so did not produce any problem producing recovered files.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 17th January 2020 at 12:11. |
![]() |
![]() |
![]() |
Tags |
recovery |
Thread Tools | Search this Thread |
Display Modes | |
|
|