Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Hi all,So this might be a little tricky to explain but I will try my best, I am looking to fulfill these requirements using S+: - Search a text file(.txt) for presence of a keyword. such as a copied word.
- Get a search result of either a boolean value(representing whether the keyword was found or not), or line number of the found keyword.
- Do step 1 and 2 in the background, meaning either without opening the text file(opening using code is fine), or opening the file in the background(file opens but does not become a foreground app) so that user does not notice and gets distracted from his work.
- This one is tricky, let me break it down, the text file is in a zip folder, that zip folder is encrypted. File is accessed normally by opening the zip(inserting password), zip is/should not be extracted(unzipped), so
- Either somehow access the text file by opening the zip using password all in the background(using code)
- Or use an opened instance of the opened text file(meaning user puts password and opens text file in, lets say Notepad++ and that file remains opened in Np++ for this use case), to search the content.
Ideally, while surfying the web user would highlight a keyword(text) and draw a gesture which would display a popup showing whether that keyword is present in the text file or not. I'm not sure if all of the steps/goals can be achieved but I'd appreciate a solution to as many of them as possible. Any reference code or plugin will be most helpful. Thanks
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Thanks for the quick reply Rob.I've managed to fulfill step 1, 2, and 3 using your guide. Here is the code: Code://function to search for text in a file
function searchFileForText(stringToSearch, filePath){
//open file to read
var sr = clr.System.IO.File.OpenText(filePath);
//stores current line
var line;
//stores current line number
var lineNumber = 0;
//tracks whether keyword is found or not
var foundFlag = false;
try{
//traverse the file
while ((line = sr.ReadLine()) != null && !foundFlag){
//increment line counter
lineNumber += 1;
//check for a keyword match in line
if ( String(line).match(stringToSearch)){
//keyword found, set flag and do stuff...
foundFlag = true;
showText("Match found at line : "+String(lineNumber)+"\nContent : "+line);
}
}
}catch{
showText("Error");
}
//close file
sr.Close();
sr.Dispose();
}
Unfortunately, step 4 remains unsolved for now. I visited that library link and its providing a .nupkg file which I believe contains source code but I cannot make sense of it. Also I was looking at stackoverflow posts regarding this and I noticed almost always the zip file is somehow unzipped and extracted to a location such as in this code: Code:string zipFile = @"C:\Users\Fesslersoft\Desktop\ZipTest\Test.zip";
string targetDirectory = @"C:\Users\Fesslersoft\Desktop\ZipTest\";
using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(zipFile))
{
zip.Password = "1234";
zip.ExtractAll(targetDirectory, Ionic.Zip.ExtractExistingFileAction.DoNotOverwrite);
}
Console.WriteLine("Zip file has been successfully extracted.");
Console.Read();
That is not the desired outcome for this use case actually, unzipping the file would mean there is a duplicate extracted folder of the same content, it would need to be deleted after every read as its an un-encrypted version of encrypted zip. Currently I am opening the zip file(not extracting), inserting password on prompt(this opens the zip in 7zip), opening the text file from 7zip, reading/editing the file, choosing update modified file in 7zip after editing so it replaces the old version with new one, and then closing the 7zip(this locks the zip file again) So I would like to open the zip file and not have to extract it temporarily at another location. Or if its not possible, having a Notepad++ instance of the text file(manually) is not a big issue for me, so if there's some way of reading that opened file it would be a great alternative as well. This is not an urgent issue so please take your time and I would appreciate a solution later.
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
Okay, first download this zip and grab the DLL out. https://www.strokesplus....ins/DotNetZip_1.16.0.zip( from project: https://github.com/haf/DotNetZip.Semverd ) NOTE: Don't put this in the Plugins folder (you can, but the script won't work without refactoring) - just put it anywhere, can even make a new folder under S+ for AdditionalReferences or something. Go to Plug-Ins > Additional References > Add Reference and select the DLL file. Then this script should work fine, at least it did for me using a standard password protected Zip file. Code://function to search for text in a file
// zipFilePath: Path to encrypted Zip file
// zipPassword: Duh
// targetFile: Name of file inside Zip file
function searchFileForText(stringToSearch, zipFilePath, zipPassword, targetFile){
//open file to read
var zipFile = Ionic.Zip.ZipFile.Read(zipFilePath);
zipFile.Password = zipPassword;
var file = zipFile.Where(x => x.FileName == targetFile).FirstOrDefault();
var stream = file.OpenReader();
var bytes = host.newArr(System.Byte, stream.Length);
stream.Read(bytes, 0, stream.Length);
stream.Close();
var fileContents = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
var fileLines = fileContents.split("\n");
//tracks whether keyword is found or not
var foundFlag = false;
try{
//traverse the file
for(var lineNumber = 0; lineNumber < fileLines.length; lineNumber++) {
//check for a keyword match in line
if ( String(fileLines[lineNumber]).match(stringToSearch)){
//keyword found, set flag and do stuff...
foundFlag = true;
showText("Match found at line : "+String(lineNumber+1)+"\nContent : "+fileLines[lineNumber]);
break;
}
}
}catch{
showText("Error");
}
}
Edited by user Friday, December 10, 2021 5:16:21 PM(UTC)
| Reason: Not specified
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Thanks a lot Rob.It is working perfectly fine. I think we are reading the file and storing its content in a variable and then searching for keyword inside it. This is good for reading(even though it takes some memory to store lines) but I'm not sure how I can use it to write to file if needed. I tried doing this to try and write to file: Code://function to insert text in a zip file
// zipFilePath: Path to encrypted Zip file
// zipPassword: Duh
// targetFile: Name of file inside Zip file
function insertInZipFile(stringToInsert, zipFilePath, zipPassword, targetFile){
//open file to write
var zipFile = Ionic.Zip.ZipFile.Write(zipFilePath);
zipFile.Password = zipPassword;
var file = zipFile.Where(x => x.FileName == targetFile).FirstOrDefault();
var stream = file.OpenWriter();
stream.Write(stringToInsert);
stream.Close();
}
But it gave me this error: Code:[ScriptEngine.Execute() - ScriptEngineException] TypeError: Ionic.Zip.ZipFile.Write is not a function
at insertInZipFile (LoadScripts:226:37) -> var zipFile = Ionic.Zip.ZipFile.Write(zipFilePath);
at Script [24]:6:1
I feel like this is close to working but I do not know the file.OpenWriter and ZipFile.Write syntax. Please help T_T
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
Are you trying to insert a new file or append to an existing file in the zip?
|
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
I am trying to append some data on the existing file. This way the file can be searched for a keyword and further more keywords(data) can be added as well. Edited by user Friday, December 10, 2021 5:32:30 PM(UTC)
| Reason: was -> way
|
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
oh no I committed an editorial sin again, now its gone for moderation.
I was saying I am trying to write to the same file.
That way a file inside an encrypted zip can be searched for a keyword and further more keywords(data) can be added as well.
|
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Also this might be a nice opportunity to ask this.. In which language should a novice programmer like myself search for solutions when trying to work with S+ scripts? I've heard you mention clearscript, I've seen javascript like codes, I know S+ works with .NET. I'm not sure if JS allows opening file streams and the syntax is always a bit different when I search for solutions online. Again, I am confused because I do not actually know which type of code(such as opening and closing files in this case) is supported by which language because I am new.
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
This worked for me - note that I'm adding a new line character to append at the end of the file: Code://function to append text in a zip file
// stringToAppend: Text to append to end of targetFile
// zipFilePath: Path to encrypted Zip file
// zipPassword: Duh
// targetFile: Name of file inside Zip file
function appendStringInZipFile(stringToAppend, zipFilePath, zipPassword, targetFile){
//open zip file
var zipFile = Ionic.Zip.ZipFile.Read(zipFilePath);
zipFile.Password = zipPassword;
var file = zipFile.Where(x => x.FileName == targetFile).FirstOrDefault();
var stream = file.OpenReader();
var bytes = host.newArr(System.Byte, stream.Length);
stream.Read(bytes, 0, stream.Length);
stream.Close();
var fileContents = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
fileContents = fileContents + "\n" + stringToAppend
zipFile.RemoveEntry(file);
zipFile.AddEntry(targetFile, fileContents);
zipFile.Save();
}
Regarding the language, ClearScript is a unique environment - especially with how much of the .NET Framework is being exposed to the engine. So the script engine itself is the Chrome V8 JavaScript engine. ClearScript creates a bridge between the JavaScript and .NET/S+ code, so it's a hybrid environment where normal JavaScript works and S+/.NET code/objects are wrapped by ClearScript to be accessible within JavaScript. Recently I changed the namespacing in the script engine so all things can be fully qualified, e.g. System.Text instead of clr.System.Text to make it a little more intuitive and natural. But still, it can be a little confusing to take some C# example code and refactor (where needed) to work in the ClearScript/JavaScript environment. Like the byte array: Code:var bytes = host.newArr(System.Byte, stream.Length);
In C# it would just be: Code:var bytes = new byte[stream.Length];
But that's not valid in JavaScript, so you call the host object - which are functions exposed by ClearScript ( https://microsoft.github...Script_HostFunctions.htm ) to have it create a .NET type, especially since the stream.Read(...) call expects a .NET System.Byte[] parameter, so you can't pass a JavaScript type to it. Now behind the scenes, ClearScript will handle type mapping automatically for base types, like numbers/strings/etc - but not a byte array. Hopefully this helps a little bit! But generally, if you find some C# code, it can usually be ported to S+ script. Edited by user Friday, December 10, 2021 8:30:18 PM(UTC)
| Reason: Not specified
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Thanks a lot Rob.It is working perfectly fine and yes what you said makes much sense now. Thanks
|
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Actually I've encountered one small issue..
Whenever I search or append data from/to file using scripts, and then open zip manually and try to save its modified version manually it gives me an error saying file is already in use. And when I reload S+ and repeat same steps it saves without any problem.
I'm guessing there is a way to close access to zip file which is missing.. similar to how we close file reading/writing streams.
|
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Originally Posted by: Rob This worked for me - note that I'm adding a new line character to append at the end of the file: Code://function to append text in a zip file
// stringToAppend: Text to append to end of targetFile
// zipFilePath: Path to encrypted Zip file
// zipPassword: Duh
// targetFile: Name of file inside Zip file
function appendStringInZipFile(stringToAppend, zipFilePath, zipPassword, targetFile){
//open zip file
var zipFile = Ionic.Zip.ZipFile.Read(zipFilePath);
zipFile.Password = zipPassword;
var file = zipFile.Where(x => x.FileName == targetFile).FirstOrDefault();
var stream = file.OpenReader();
var bytes = host.newArr(System.Byte, stream.Length);
stream.Read(bytes, 0, stream.Length);
stream.Close();
var fileContents = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
fileContents += fileContents + "\n" + stringToAppend
zipFile.RemoveEntry(file)
zipFile.AddEntry(targetFile, fileContents);
zipFile.Save();
}
Regarding the language, ClearScript is a unique environment - especially with how much of the .NET Framework is being exposed to the engine. So the script engine itself is the Chrome V8 JavaScript engine. ClearScript creates a bridge between the JavaScript and .NET/S+ code, so it's a hybrid environment where normal JavaScript works and S+/.NET code/objects are wrapped by ClearScript to be accessible within JavaScript. Recently I changed the namespacing in the script engine so all things can be fully qualified, e.g. System.Text instead of clr.System.Text to make it a little more intuitive and natural. But still, it can be a little confusing to take some C# example code and refactor (where needed) to work in the ClearScript/JavaScript environment. Like the byte array: Code:var bytes = host.newArr(System.Byte, stream.Length);
In C# it would just be: Code:var bytes = new byte[stream.Length];
But that's not valid in JavaScript, so you call the host object - which are functions exposed by ClearScript ( https://microsoft.github...Script_HostFunctions.htm ) to have it create a .NET type, especially since the stream.Read(...) call expects a .NET System.Byte[] parameter, so you can't pass a JavaScript type to it. Now behind the scenes, ClearScript will handle type mapping automatically for base types, like numbers/strings/etc - but not a byte array. Hopefully this helps a little bit! But generally, if you find some C# code, it can usually be ported to S+ script. Small correction of a typo for anyone using this code, replace: Code:fileContents += fileContents + "\n" + stringToAppend
with: Code:fileContents = fileContents + "\n" + stringToAppend;
or: Code:fileContents += "\n" + stringToAppend;
otherwise it would multiply file's previous content(and thus size) by 2 every time data is appended. also a missing semicolon here: Code:zipFile.RemoveEntry(file);
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
Originally Posted by: randomConstant Originally Posted by: Rob This worked for me - note that I'm adding a new line character to append at the end of the file:
Code://function to append text in a zip file
// stringToAppend: Text to append to end of targetFile
// zipFilePath: Path to encrypted Zip file
// zipPassword: Duh
// targetFile: Name of file inside Zip file
function appendStringInZipFile(stringToAppend, zipFilePath, zipPassword, targetFile){
//open zip file
var zipFile = Ionic.Zip.ZipFile.Read(zipFilePath);
zipFile.Password = zipPassword;
var file = zipFile.Where(x => x.FileName == targetFile).FirstOrDefault();
var stream = file.OpenReader();
var bytes = host.newArr(System.Byte, stream.Length);
stream.Read(bytes, 0, stream.Length);
stream.Close();
var fileContents = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
fileContents += fileContents + "\n" + stringToAppend
zipFile.RemoveEntry(file)
zipFile.AddEntry(targetFile, fileContents);
zipFile.Save();
}
Regarding the language, ClearScript is a unique environment - especially with how much of the .NET Framework is being exposed to the engine. So the script engine itself is the Chrome V8 JavaScript engine. ClearScript creates a bridge between the JavaScript and .NET/S+ code, so it's a hybrid environment where normal JavaScript works and S+/.NET code/objects are wrapped by ClearScript to be accessible within JavaScript. Recently I changed the namespacing in the script engine so all things can be fully qualified, e.g. System.Text instead of clr.System.Text to make it a little more intuitive and natural. But still, it can be a little confusing to take some C# example code and refactor (where needed) to work in the ClearScript/JavaScript environment. Like the byte array: Code:var bytes = host.newArr(System.Byte, stream.Length);
In C# it would just be: Code:var bytes = new byte[stream.Length];
But that's not valid in JavaScript, so you call the host object - which are functions exposed by ClearScript ( https://microsoft.github...Script_HostFunctions.htm ) to have it create a .NET type, especially since the stream.Read(...) call expects a .NET System.Byte[] parameter, so you can't pass a JavaScript type to it. Now behind the scenes, ClearScript will handle type mapping automatically for base types, like numbers/strings/etc - but not a byte array. Hopefully this helps a little bit! But generally, if you find some C# code, it can usually be ported to S+ script. Small correction of a typo for anyone using this code, replace: Code:fileContents += fileContents + "\n" + stringToAppend
with: Code:fileContents = fileContents + "\n" + stringToAppend;
or: Code:fileContents += "\n" + stringToAppend;
otherwise it would multiply file's previous content(and thus size) by 2 every time data is appended. also a missing semicolon here: Code:zipFile.RemoveEntry(file);
Thank you for your this kind nice discussion. Do you know how to count the files in the zip? I want the result to judge that is there only one fold in the zip or some files in the zip? Do you know
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
On my phone so I can't test, but it's probably.
zipFile.Count
Or
zipFile.Count()
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
Originally Posted by: Rob On my phone so I can't test, but it's probably.
zipFile.Count
Or
zipFile.Count() Tested. zipFile.Count seem to be working fine.
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
Emmm, it shows an Error 'Ionic is not defined', but I added the DLL file into the Plug-in as Rob said. And how to judge that is there only one fold or one file or are there some files in the zip?
|
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
hmm try this code, its a function that takes zip file path and optional password as input and returns total number of files+folders inside it. Code://count number of files in a zip file
// zipFilePath: Path to encrypted Zip file
// zipPassword: Duh
function countFilesInZipFile(zipFilePath, zipPassword = ""){
//open file to read
var zipFile = Ionic.Zip.ZipFile.Read(zipFilePath);
zipFile.Password = zipPassword;
return zipFile.Count
}
zip files actually show files and folders names, and their sizes when encrypted (7zip does not) so you don't actually need password. Hope it helps.
|
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
oh and put the contents of function in a try-catch block because it can throw a runtime error if file path is incorrect.
|
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
and put the DLL as an additional reference from the Plugins section of S+, maybe you mistakenly added it as a plugin.
|
1 user thanked randomConstant for this useful post.
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
Originally Posted by: randomConstant and put the DLL as an additional reference from the Plugins section of S+, maybe you mistakenly added it as a plugin. Ohhhhhh, I see, and I really miss the AdditionalReferences. Now it is normal. Thank you randomConstant. I took a look at the Github page just now, and I didn't find how to get the name or type of the file(s) in the zip. In another post, Rob helped to the code that unzips the file to the current fold and adds a new fold or just the current fold. I want to judge the file count and the type of the file in the zip to achieve to unzip in the following three conditions, so now I need the type of the file(s) in the zip 1 Only one file a, Unzip to the current fold b, If the file exists, then rename it by the name add(1) 2 Only one fold a, Unzip to the current fold directly b, If the fold exists, the new fold name add(1) 3 Some files with fold(s) a, Unzip to the new fold with the zip file name b, If the fold exists, the new fold name add(1)
|
|
|
|
Rank: Advanced Member
Groups: Translators, Approved Joined: 7/17/2021(UTC) Posts: 135
Thanks: 35 times Was thanked: 18 time(s) in 15 post(s)
|
I would like to mention zipFile.Count returns count of all the files and folders in the zip, so if zip contains a folder and then 2 files and 2 folders inside that folder, you will get a total count of 5. I'm not sure about file type detection using this plugin though so Rob will probably help you out.
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
I find some codes to identify the file(s) that is a fold or not in the zip by C#.
Code:static class ZipArchiveEntryExtensions
{
public static bool IsFolder(this ZipArchiveEntry entry)
{
return entry.FullName.EndsWith("/");
}
}
Code:using (var archive = ZipFile.OpenRead("bla.zip"))
{
foreach (var s in archive.Entries)
{
if (s.IsFolder())
{
// do something special
}
}
}
I try to like this in S+net, and it shows the filenames and IsDirectory. Code:var wnd = sp.ForegroundWindow();
var selectedFiles = sp.GetSelectedFilesInExplorer(wnd.HWnd);
var fullPath = selectedFiles[0];
var zipFile = Ionic.Zip.ZipFile.Read(fullPath);
//var entry = zipFile.Entries;
var s;
var n = zipFile.Count
var str = "";
var bool = "";
var delim = "";
//Loop through each item
zipFile.forEach(function(s)
{
str = str + delim + entry.FileName;
bool = bool + delim + entry.IsDirectory;
delim = "\r\n";
});
sp.MessageBox(str + bool, 'Message');
Edited by user Thursday, December 23, 2021 11:20:39 AM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
Here's an example to get you started: Code:var p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "C:\\Program Files\\7-Zip\\7z.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "l C:\\Temp\\test.rar"
p.Start();
var output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
var lines = output.split(/\r\n|\n\r|\n|\r/);
// skipping last line to ignore the summary line
// but yeah, tweak as needed
for(var i = 0; i < lines.length - 2; i++) {
if(/^[0-9]{4}-/.test(lines[i])) {
StrokesPlus.Console.Log(lines[i]);
}
}
|
2 users thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
Thank you so so so much, Rob. Now it is normal. Code:var wndHandle = sp.ForegroundWindow().HWnd;
var desktopHandle = sp.DesktopWindowListView().HWnd;
var fullPath = "";
var selectedFiles;
var isDesktop = false;
//if(wndHandle.ToInt32() == desktopHandle.ToInt32() || sp.LastFocusControl().HWnd.ToInt32() == desktopHandle.ToInt32()) {
if(wndHandle.ToInt32() == desktopHandle.ToInt32() || sp.LastFocusControl().HWnd.ToInt32() == desktopHandle.ToInt32()) {
//Desktop
selectedFiles = sp.GetSelectedFilesOnDesktop();
isDesktop = true;
} else {
//Not Desktop
selectedFiles = sp.GetSelectedFilesInExplorer(wndHandle);
}
fullPath = selectedFiles[0];
if(isDesktop) {
fullPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\" + fullPath;
}
var path = fullPath.replaceAll("\\","\\\\")
var p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "C:\\Program Files\\7-Zip\\7z.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "l \"" + path + "\""
p.Start();
var output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
var lines = output.split(/\r\n|\n\r|\n|\r/);
// skipping last line to ignore the summary line
// but yeah, tweak as needed
for(var i = 0; i < lines.length - 1; i++) {
if(/^[0-9]{4}-/.test(lines[i])) {
StrokesPlus.Console.Log(lines[i]);
}
}
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close