I’m trying to use the Windows findstr command to search for a string and save the results to an output file.
findstr /i /n /d:{sourcepath$} "my text to search" . >{sourcepath$}\output.txt
If I run the command using typed out paths in a command window it works fine. I’m now trying to add it to a button in dopus but it doesn’t create the output file.
I’ve tried using an explicit path instead of {sourcepath$} when redirecting output to a file but it doesn’t make any difference.
Ultimately, I want to use this with a file collection, will there be any issue with this? The file collection is created from a search (including searching in compressed files).
The sourcepath$ variable isn’t working with the windows findstr command. If I use an explicit path for the first path the command runs ok and I get lines in the output.txt file. When I replace the first path with {sourcepath$} I get a FINDSTR: Bad command line error and the output.txt file is empty.
Here is the command I have in the button with personal information replaced with x’s.
Eventually I want to use this with file collections but when testing I’m getting the same error for this as well. Is sourcepath$ the correct thing to use when running this with a file collection?
The noterm modifier has fixed the problem and the command runs fine now, thanks.
I guess I will need to use a file collection initially to find the files I need and then temporarily copy them to a folder before running the command on that folder.
You can probably run the command once for each file, which would work in collections. (With a slightly different command-line, of course.)
If you delete the output file at the start and then use >> instead of > to redirect to it, the command run for each individual file will append to the output instead of overwriting it.
With your earlier comment about the findstr command not working with collections as it wouldn’t understand them, how would running findstr once for each file work with collections?
Are you suggesting some kind of loop that reads down the list of files stored in a collection and then after each run append the results to an output file? What would be the process of reading down each file in a collection to pass to findstr?
No need for explicit loops. If you use a single-file code like {filepath} in a button, Opus will automatically run that line of the button once per selected item.
You can also loop through the files using scripting if you want to do something more complex, but it probably wouldn't be needed here. You can delete the existing output file (if any) on line 1, then run findstr on each file on line 2 without any loop or scripting.