Jump to content

Is it possible to find all hip files using a specific operator?


magneto

Recommended Posts

Guest mantragora

GREP Powershell way:

 

Grep.ps1

# directory to search thru
$path = "E:\OneDrive\Programs\Houdini\ManyHips"

# file type to search
$extension = ".hipnc"

# operator type to find
$lookfor = "Vop/negate"
#----------------------------------------
 
# cls
Clear-Host
 
# filter and collect
$result = Get-ChildItem $path -Recurse | Where-Object {$_.Extension -eq $extension} | Select-String $lookfor -CaseSensitive
 
# format output
$result | Format-Table -Property Filename, LineNumber, Pattern -AutoSize

Output after execution:

Filename                                                        LineNumber         Pattern
--------                                                        ----------         -------
wrap.hipnc                                                      47                 Vop/negate
wrap.hipnc                                                      48                 Vop/negate
wrap.hipnc                                                      115                Vop/negate
Test.hipnc                                                      104                Vop/negate
Edited by mantragora
  • Like 1
Link to comment
Share on other sites

Thanks mantragora you are a master :) I am a PS noob. Do you know how to run your file and let the window stay rather than exit immediately? Just running works but then the window appears for a split second.

 

Also how can I use multiple formats? hip and hipnc?

 

EDIT: Ok I found one way to see the results using cmd :)

PowerShell -NoExit -File "C:\SomeFolder\SomePowerShellScript.ps1"

Edited by magneto
Link to comment
Share on other sites

Guest mantragora

Fast modification:

$path = "C:\Users\mantragora\Desktop\HIPY"
$lookfor = "Vop/negate"
$extension = ".hip"
 
# cls
Clear-Host
 
# filter and collect
$result = Get-ChildItem $path -Recurse | Where-Object {$_.Extension -Match $extension} | Select-String $lookfor -CaseSensitive
 
# format output
$result | Format-Table -Property Filename, LineNumber, Pattern -AutoSize
 
# pause
Read-Host "Press <Enter> to exit"
  • Like 1
Link to comment
Share on other sites

Guest mantragora

To be fair my advice is to not use Powershell scripts by just running them, instead run Powershell shell and drag and drop script there. Reason for this is that you can have extended logic built in into script that will trigger different behaviour based on parameters that you will pass to script or override. And it does have autocompletion. Calling script and putting "-" + TAB will browse thru available Flags you can set. 

 

I'm using something similar to compile HDK library of my custom extensions. I can specify many additional flags, for example I can run:

 

MAKE -Filter "SOP"

to compile only SOP part of library. Or I can:

MAKE -Filter "S" 

to compile all parts of library that starts on "S", that means SOP, SHOP. Not adding "-Filter" flag will compile whole library.

 

If compilation fails I can add:

MAKE -Filter "SOP" -CreateReport

so it would create report file with compiler output that I can browse thru.

 

Those are all optional things you cannot use easily by just running file.

  • Like 1
Link to comment
Share on other sites

Guest mantragora

Consider this:

# ------------------------------------------------------------------------------------------------- #
# FLAGS:
# Path                  - <string> directory to search thru
# ExtensionPattern      - <string> file type to search
# LookForPattern        - <string> text we want to find
# Recurse		- <switch> if set fill search also in subdirectories
# MatchExtensionPattern - <switch> if set will find any extension that contains specified pattern,
#                         otherwise will match exactly specified pattern
#
# ------------------------------------------------------------------------------------------------- #

Param 
(
	[string] $Path = 'E:\Dropbox',
	[string] $ExtensionPattern = '.hip',
	[string] $LookForPattern = 'type = file',
	[switch] $Recurse,
	[switch] $MatchExtensionPattern
)

# ----------------- DO NOT CHANGE THE CODE BELOW IF YOU DON'T KNOW WTF YOU ARE DOING -----------------
 
# cls
Clear-Host
 
# collect files
$files = if ($Recurse) { Get-ChildItem -path $Path -recurse -file } else { Get-ChildItem -path $Path -file }

# filter 
$result = $files | Where-Object { if ($MatchExtensionPattern) {$_.Extension -match $ExtensionPattern} else {$_.Extension -eq $ExtensionPattern} } | Select-String -pattern $LookForPattern -casesensitive

# format output
if ($result.Count -gt 0) 
{ 
	Write-Host ([string]::Format('Found {0} files with "{1}" extension and "{2}" pattern.', $result.Count, $ExtensionPattern, $LookForPattern)) -backgroundcolor "green" -foregroundcolor "black" 
	$result | Format-Table -property FileName, LineNumber, Pattern -autosize 
}
else { Write-Host ([string]::Format('Found {0} files with "{1}" extension and "{2}" pattern.', $result.Count, $ExtensionPattern, $LookForPattern)) -backgroundcolor "red" -foregroundcolor "black" }

# pause
#Read-Host "Press <Enter> to exit"
EDIT: It looks that only VOP nodes can be found by using "Vop/foo" pattern, eg: "Vop/negate" . For other operators you have to use "type = foo", eg: "type = transform". Edited by mantragora
  • Like 1
Link to comment
Share on other sites

Guest mantragora

WTF? Ok, there is something wrong with formating when you are using "<code></code>"

tag. There should be couple lines of code below my last code and they where not posted. It happened second time in this topic. They where eaten.

Anyway, try to run last code with:

grep.ps1 -MatchExtensionPattern
and without it:

grep.ps1
in directory that contains both, ".hip" and ".hipnc" file types, and compare output.

This script doesn't have to be limited to ".hip" fils only, so you can override other flags and do:

grep.ps1 -Path 'D:\PornTapes' -ExtensionPattern '.txt' -LookForPattern 'Magneto is not my name'
to search thru ".txt" files in wherever you are keeping your porn tapes.

Also notice how you can browse thru available flags that you can pass to script while you add "-"+TAB after script name (in powershell shell of course, not while just running script).

Edited by mantragora
  • Like 1
Link to comment
Share on other sites

Guest mantragora

If it was turned off you may have to setup it correctly to run scripts with it at all. Run shell with Admin Rights and write

Get-ExecutionPolicy
and if it's not set to "RemoteSigned" than do

Set-ExecutionPolicy -RemoteSigned
this will allow to run scripts that have no M$ certificate or something like that.
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...