magneto Posted September 28, 2014 Share Posted September 28, 2014 Hi, For example let's say the hip file uses mysop,otl, would it be possible to do a search in a directory and filter the hip files that uses this mysop operator? Opening them one by one is slow. Thanks. Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted September 28, 2014 Share Posted September 28, 2014 (edited) 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 September 28, 2014 by mantragora 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted September 28, 2014 Author Share Posted September 28, 2014 (edited) 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 September 28, 2014 by magneto Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted September 28, 2014 Share Posted September 28, 2014 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" 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted September 28, 2014 Author Share Posted September 28, 2014 Thanks mantragora, it works I will add PS to the growing list of things to learn Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted September 28, 2014 Share Posted September 28, 2014 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. 1 Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted September 28, 2014 Share Posted September 28, 2014 (edited) 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 October 2, 2014 by mantragora 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted September 28, 2014 Author Share Posted September 28, 2014 Thanks mantragora, I tried dragging the file first but I had PS disabled on my system so I enabled that after I found the cmd method Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted September 28, 2014 Share Posted September 28, 2014 (edited) 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 October 2, 2014 by mantragora 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted September 28, 2014 Author Share Posted September 28, 2014 Haha thanks man I found that PS was disabled by default on win 7 at least. Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted September 28, 2014 Share Posted September 28, 2014 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. 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted September 28, 2014 Author Share Posted September 28, 2014 Thanks mantragora, that's what I did as well. It works now, just shows that I never used PS on my system before Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.