FINDSTR "out of memory" and "cannot open" files
Posted: 28 Sep 2022 13:49
Dear DOS experts,
I'm writing these lines in hope that someone here will pick up on this and help me understand what's going on with this FINDSTR command. I wrote a more detailed post about this on Reddit. While I did get a few upvotes, no one took time or interest in replying to me. Maybe no one knows the answer?
Basically, I have a file and folder structure that looks like this.
It's two sets of folders, each containing a few thousand subfolders, and in each of those are a handful of text files.
Starting from the root folder (Main Folder in this example), I am trying to use FINDSTR with the /S option to recursively search all the files within this tree structure for a specific string. But it fails with "out of memory" after 17 "cannot open".
However if I point it directly at any one file of interest, it does find what I'm looking for. So it's not that the files don't exist. It seems to be more of a problem with traversing the folder structure.
I have already found a PowerShell alternative to this that does what I want. But I was curious why FINDSTR is failing? Both folder names and file name consist of only English alphabet characters, dashes, dots, parentheses and square brackets. Could this be the offending factor?
I did find the Q&A style post of "biblical proportions" by one of your regular users on this forum, and it implicates /S option as being problematic. Although I don't quite understand how? Can someone give me an example with my use case in mind? Can I not use this option for "matching files in the current directory and all subdirectories" like it says in the help section? Or does this mean something special and not what I expect?
Also, how do you run out of memory running such a command? I speculate it might be because I am running this on a large number of files (even though it's finding none!). But I have 32 GB of RAM and only half of that is in use. I'm not sure if this is what "memory" means in this context, but I have plenty of it.
Help me DOS experts, you're my only hope.
Regards,
Ken
I'm writing these lines in hope that someone here will pick up on this and help me understand what's going on with this FINDSTR command. I wrote a more detailed post about this on Reddit. While I did get a few upvotes, no one took time or interest in replying to me. Maybe no one knows the answer?
Basically, I have a file and folder structure that looks like this.
Code: Select all
C:.
└───Main Folder
├───Folder 1
│ ├───Folder 1
│ │ file 1.txt
│ │ file 2.txt
│ │ file 3.txt
│ │
│ ├───Folder 2
│ │ file 1.txt
│ │ file 2.txt
│ │ file 3.txt
│ │
│ └───Folder 3
│ file 1.txt
│ file 2.txt
│ file 3.txt
│
└───Folder 2
├───Folder 1
│ file 1.txt
│ file 2.txt
│ file 3.txt
│
├───Folder 2
│ file 1.txt
│ file 2.txt
│ file 3.txt
│
└───Folder 3
file 1.txt
file 2.txt
file 3.txt
Starting from the root folder (Main Folder in this example), I am trying to use FINDSTR with the /S option to recursively search all the files within this tree structure for a specific string. But it fails with "out of memory" after 17 "cannot open".
Code: Select all
C:\Users\Ken\Desktop\DataMigration\Merge>findstr.exe /s "Project.45" *.txt
FINDSTR: Cannot open ParentFolder 1\Adam\Adams Folder\file.txt
FINDSTR: Cannot open ParentFolder 1\Ben\Bens Folder\file.txt
FINDSTR: Cannot open ParentFolder 1\Charlie\Charlies Folder\file.txt
FINDSTR: Cannot open ParentFolder 2\David\Davids Folder\file.txt
FINDSTR: Cannot open ParentFolder 2\Eric\Erics Folder\file.txt
FINDSTR: Cannot open ParentFolder 2\Freddie\Freddies Folder\file.txt
...
FINDSTR: Out of memory
I have already found a PowerShell alternative to this that does what I want. But I was curious why FINDSTR is failing? Both folder names and file name consist of only English alphabet characters, dashes, dots, parentheses and square brackets. Could this be the offending factor?
I did find the Q&A style post of "biblical proportions" by one of your regular users on this forum, and it implicates /S option as being problematic. Although I don't quite understand how? Can someone give me an example with my use case in mind? Can I not use this option for "matching files in the current directory and all subdirectories" like it says in the help section? Or does this mean something special and not what I expect?
Also, how do you run out of memory running such a command? I speculate it might be because I am running this on a large number of files (even though it's finding none!). But I have 32 GB of RAM and only half of that is in use. I'm not sure if this is what "memory" means in this context, but I have plenty of it.
Help me DOS experts, you're my only hope.
Regards,
Ken