Jump to content
Deye

wicked thing (Example)

Recommended Posts

Posted (edited)

 

; https://www.autoitscript.com/forum/topic/202387-wicked-thing-example/

#include <Array.au3>

;~ $DirPath = @DesktopDir
$DirPath = @ScriptDir
$sPath = " -Path " & $DirPath & " "
$sPath = "" ;search  @ScriptDir

$i = 3  ;search for files Levels Deep From $DirPath
$iDepth = " -Depth " & $i
$iDepth = " -Recurse"   ; search all ;skip functionality of Level stop

$Extension = '".au3",".txt"' ;not applicable yet need to find something that will work for multi extentions
$Extension = '.au3'

$fileExtension = "| Where-Object{$_.extension -eq '" & $Extension & "'}"
$fileExtension = "" ; Get all Types

Local $sTimeSpan[4] = ["Hours", "Days", "Months", "Years"]
$sTimeSpan = $sTimeSpan[0]
$iCountSelect = -12 ;last $sTimeSpan = 12 Hours
$iCountSelectTimeSpan = "| where {!$_.PSIsContainer -AND $_.lastwritetime -gt (get-date).add" & $sTimeSpan & "('" & $iCountSelect & "')}"
;~ $iCountSelectTimeSpan = ""   ;skip functionality

;List First file found Hits
$iHits = 5
$DislpayiHits = "|Select-Object -First " & $iHits
$DislpayiHits = ""    ; deactivate

; search filenames that have *text* in their name
$sfilenameLike = '*text*'
$sfilename1 = "| where {$_.Name -like '" & $sfilenameLike & "'}"
$sfilename1 = ""    ;skip functionality

; search filenames by expr just Use $sfilename1 or both ;)
$sfilenameMatch = '^text'
$sfilename2 = "| where {$_.Name -match  '" & $sfilenameMatch & "'}"
$sfilename2 = ""    ;skip functionality

$sSearchString = "hello" ;search in files for instance "<strings.au3>"
$sSearch = "| Where-Object { $_ | Select-String -Pattern '" & $sSearchString & "' }"
If Not $fileExtension Then $sSearch = ""
$sSearch = ""    ; deactivate search  ;Optional - Not to search in files thus the remaining function will only list latest (if Default)

; Sort list to most Recent first to the top of the list
$bLatest = "| Sort-Object -Descending lastwritetime"
$PSI = "| Where-Object { !$_.PSIsContainer} " ;  Default

ConsoleWrite(@CRLF & "Path = " & @TAB & ($sPath ? $DirPath : @ScriptDir) & @CRLF)
ConsoleWrite("filename1 = " & @TAB & ($sfilename1 ? $sfilenameLike : False) & @CRLF)
ConsoleWrite("filename2 = " & @TAB & ($sfilename2 ? $sfilenameMatch : False) & @CRLF)
ConsoleWrite("Extension = " & @TAB & ($fileExtension ? $Extension : False) & @CRLF)
ConsoleWrite("Search = " & @TAB & ($sSearch ? $sSearchString : False) & @CRLF)
ConsoleWrite("CountBack = " & @TAB & ($iCountSelectTimeSpan ? "Last " & $sTimeSpan & ":" & $iCountSelect : False) & @CRLF)
ConsoleWrite("Level Depth = " & @TAB & ($iDepth ? $i : False) & @CRLF)
ConsoleWrite("Hits = " & @TAB & ($DislpayiHits ? $iHits : False) & @CRLF)


$sCommands = $sPath & $iDepth & $sfilename1 & $sfilename2 & $fileExtension & $PSI & $iCountSelectTimeSpan & $sSearch & $DislpayiHits & $bLatest & " | foreach {$_.FullName}"
$sCommands = 'powershell -Command "Get-ChildItem' & $sCommands
$iPID = Run(@ComSpec & " /c " & $sCommands, "", @SW_HIDE, $stdout_child)
$sOutput = ""

While 1
    $sOutput &= StdoutRead($iPID)
    If @error Then
        ExitLoop
    EndIf
WEnd

Local $Array[0][2]
_ArrayAdd($Array, $sOutput, "|")
_ArrayColDelete($Array, 1)
_ArrayDisplay($Array)

 

Edited by Deye
Updated - yet again

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...