Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Management.Automation;
- using System.Management.Automation.Runspaces;
- using System.Collections.ObjectModel;
- namespace WindowsFormsApplication1
- {
- public partial class Form3 : Form
- {
- public Form3()
- {
- InitializeComponent();
- label5.Hide();
- label6.Hide();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
- {
- System.Windows.Forms.DialogResult result = dialog.ShowDialog();
- label5.Text = dialog.SelectedPath;
- label5.Show();
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- this.Hide();
- Form1 myForm = new Form1();
- myForm.Show();
- }
- private void button5_Click(object sender, EventArgs e)
- {
- this.Hide();
- Form1 myForm = new Form1();
- myForm.Show();
- }
- private void button6_Click(object sender, EventArgs e)
- {
- this.Hide();
- Form3 myForm = new Form3();
- myForm.Show();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- using (var dialog = new System.Windows.Forms.OpenFileDialog())
- {
- System.Windows.Forms.DialogResult result = dialog.ShowDialog();
- label6.Text = dialog.FileName;
- label6.Show();
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- string filter = textBox1.Text;
- string folder = label5.Text;
- string output = label6.Text;
- String[] substrings = folder.Split('\\');
- folder = "";
- foreach(string substring in substrings){
- folder = folder + substring + "\\" + "\\";
- }
- String[] substringsOutput = output.Split('\\');
- output = "";
- foreach (string substringOutput in substringsOutput)
- {
- output = output + substringOutput + "\\" + "\\";
- }
- output = output.Remove(output.Length - 2);
- Runspace runspace = RunspaceFactory.CreateRunspace();
- runspace.Open();
- Pipeline pipeline = runspace.CreatePipeline();
- var filterEscaped = "\"" + filter + "\\" + "\"";
- string jqExecuteCommand = "jq -r 'select(.text | tostring | contains(\\" + filterEscaped + ")) | [.text] | select(length > 0) | @csv' " + " $files[$i].FullName " + " >> " + output;
- string fileLoopCommand = "$files = Get-ChildItem " + folder + " -Recurse -Include *.json" + "\n" + "for($i=0; $i -lt $files.Count; $i++) {" + jqExecuteCommand +"}";
- pipeline.Commands.AddScript(fileLoopCommand);
- pipeline.Commands.Add("Out-String");
- Collection<PSObject> results = pipeline.Invoke("Set-ExecutionPolicy Unrestricted");
- runspace.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement