CMD Search from list of partial filenames and copy matches?

General discussion related to "Everything".
Post Reply
Vortex
Posts: 11
Joined: Tue Aug 30, 2016 9:26 am

CMD Search from list of partial filenames and copy matches?

Post by Vortex »

I want to search from a list of partial filenames and copy the matches to another folder. Can I do this with Everything from the command line?

The list is bar delimited. Each line contains a name and a Title, for example:

Code: Select all

    A Name|The Title
The actual filenames have other stuff in them as well, but all start with the name and have the delimiter " - " and contain the title after, for example:

Code: Select all

    A Name - The Title- subtitle (html).rar
I need to search from a folder that contains 20K subfolders and 500K files. The list has 120K entries. The files are various text formats.

Is this possible?
Thanks.
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: CMD Search from list of partial filenames and copy matches?

Post by NotNull »

Vortex wrote:Is this possible?
Thanks.
Yes, that is possible!
There you go: question answered, problem solved; you're welcome! :D 8-)

A bit more serious:
I think that will be about 10 lines of code (maybe less)
How is your experience with CMD? What have you tried thus far?
Vortex
Posts: 11
Joined: Tue Aug 30, 2016 9:26 am

Re: CMD Search from list of partial filenames and copy matches?

Post by Vortex »

Hi, Thanks for your reply. My knowledge of cmd line code is not too bad. I've tried using these 2 scripts:

https://stackoverflow.com/questions/383 ... tial-names
https://stackoverflow.com/questions/173 ... and-copy-t

but because I have so many files and subfolders it never gets past the first one on the list. I can actually manually find them faster with Everything than those scripts can!
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: CMD Search from list of partial filenames and copy matches?

Post by NotNull »

WARNING: NOT TESTED

This is to give you an idea
In this version, it does not change (copy) anything on your system.
This will build a list of all found files in memory and write them to disk (%OUTPUT%) when done

Change the settings to your situation.

TEST.CMD

Code: Select all

@echo off
:: SETTINGS
   set FOLDER=c:\temp
   set ES=c:\tools\everything\ES.exe
   set INPUT=searchsrtings.txt
   set OUTPUT=filelist.txt

::ACTION
   (for /f "tokens=1,2 delims=|" %%x in (%INPUT%) DO "%ES%" -path "%FOLDER%" "%%x - %%y") >> "%OUTPUT%"


If this works, adding the copy part isn't very hard. Please report back.
Vortex
Posts: 11
Joined: Tue Aug 30, 2016 9:26 am

Re: CMD Search from list of partial filenames and copy matches?

Post by Vortex »

That fails with the error:
"Unable to open the list:C:\Users\-\Desktop\A Name - The Title is not a valid file list."

The list is partial filenames - There doesn't seem to be any wildcards in the code?

You spelt searchstrings wrong by the way.
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: CMD Search from list of partial filenames and copy matches?

Post by NotNull »

Vortex wrote:That fails with the error:
"Unable to open the list:C:\Users\-\Desktop\A Name - The Title is not a valid file list."
You need ES.exe, the command;line tool. I think tou tried it with Everything.exe
You spelt searchstrings wrong by the way.
If that is all I misspelled, it's a good day! I make tons of typo's (but strange enough hardly any when writing code)

But like I said: "This is to give you an idea". I spent ~15 minutes writing the original message. And that includes writing the script.
You said you know your way around CMD, so I thought that would be enough to get you started.
Vortex
Posts: 11
Joined: Tue Aug 30, 2016 9:26 am

Re: CMD Search from list of partial filenames and copy matches?

Post by Vortex »

I didn't realise there is a separate command line tool for Everything. With that installed I get:
"The system cannot find the path specified.
Press any key to continue . . ."
It repeats that for as many lines as are on the list.

I presume the

Code: Select all

"set FOLDER=c:\temp" 
part of your code refers to the folder where the files I want to search are located?

I've tried adding files to the search folder that are on the list but it never finds anything.
I added:

Code: Select all

A Name|The Title
to the top of the list and made a text file with the filename:

Code: Select all

A Name - The Title.txt 
and put that in the "set folder" but it still just repeats
"The system cannot find the path specified.
Press any key to continue . . ."
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: CMD Search from list of partial filenames and copy matches?

Post by NotNull »

Did you try to debug the script? (replace echo off with echo on; ES.EXE ... command with echo ES.EXE ... command ; ...)

Tested this and it turns out it works OK. These were my steps:


[*] I created a folder "C:\temp"
[*] Created an IN.txt and an TEST.cmd in this folder with contents:
IN.txt

Code: Select all

The Name|The Title
A Name|A Title
This One|Doesn't Exist
TEST.cmd

Code: Select all

@echo off
:: SETTINGS
   set FOLDER=c:\temp
   set ES=c:\tools\everything\ES.exe
   set INPUT=IN.txt
   set OUTPUT=OUT.txt

::ACTION
   (for /f "tokens=1,2 delims=|" %%x in (%INPUT%) DO "%ES%" -path "%FOLDER%" "%%x - %%y") > "%OUTPUT%"
[*] I created a folder "C:\temp\search here"

[*]In that folder I created 3 empty files:
- "A Name - A Title - some other text.txt"
- "Some random file.txt"
- "The Name - The Title (blabla).txt"


Searching for:
The Name|The Title
A Name|A Title
This One|Doesn't Exist

In a folder containing:
"A Name - A Title - some other text.txt"
"Some random file.txt"
"The Name - The Title (blabla).txt"

Should result n 2 foud files.


After running TEST.cmd this was in OUT.txt:

Code: Select all

C:\temp\SEARCH HERE\The Name - The Title (blabla).txt
C:\temp\SEARCH HERE\A Name - A Title - some other text.txt
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: CMD Search from list of partial filenames and copy matches?

Post by NotNull »

BTW: I just noticed taht %INPUT% doesn't allow filenames with spaces in it.
Rename your inputfileor change the relevant line in the script to:

Code: Select all

  (for /f "usebackq tokens=1,2 delims=|" %%x in ("%INPUT%") DO "%ES%" -path "%FOLDER%" "%%x - %%y") > "%OUTPUT%"
HTH ..
Vortex
Posts: 11
Joined: Tue Aug 30, 2016 9:26 am

Re: CMD Search from list of partial filenames and copy matches?

Post by Vortex »

Thanks. I repeated your steps using all the same code and filenames.

Code: Select all

C:\temp>set FOLDER=c:\temp

C:\temp>set ES=c:\tools\everything\ES.exe

C:\temp>set INPUT=IN.txt

C:\temp>set OUTPUT=OUT.txt

C:\temp>(for /F "tokens=1,2 delims=|" %x in (IN.txt) DO "c:\tools\everything\ES.
exe" -path "c:\temp" "%x - %y" ) 1>"OUT.txt"
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.

C:\temp>pause
Press any key to continue . . .
OUT.txt:

Code: Select all

C:\temp>"c:\tools\everything\ES.exe" -path "c:\temp" "The Name - The Title" 
C:\temp>"c:\tools\everything\ES.exe" -path "c:\temp" "A Name - A Title" 
C:\temp>"c:\tools\everything\ES.exe" -path "c:\temp" "This One - Doesn't Exist" 
Your last change in the code made no difference. Any idea what I'm doing wrong
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: CMD Search from list of partial filenames and copy matches?

Post by NotNull »

Code: Select all

set ES=c:\tools\everything\ES.exe
Is the ES.EXE tool actually installed in the folder C:\tools\Everything?
If not, you have to chan ge this setting to the actual path
Vortex
Posts: 11
Joined: Tue Aug 30, 2016 9:26 am

Re: CMD Search from list of partial filenames and copy matches?

Post by Vortex »

Sorry, my bad, it was in "c:\tools\ES.exe"

OUT.txt still looks different to you results, or did you edit the other stuff out?

Code: Select all

C:\temp>"c:\tools\everything\ES.exe" -path "c:\temp" "The Name - The Title" 
C:\temp\search here\The Name - The Title (blabla).txt

C:\temp>"c:\tools\everything\ES.exe" -path "c:\temp" "A Name - A Title" 
C:\temp\search here\A Name - A Title - some other text.txt

C:\temp>"c:\tools\everything\ES.exe" -path "c:\temp" "This One - Doesn't Exist" 
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: CMD Search from list of partial filenames and copy matches?

Post by NotNull »

Vortex wrote:Sorry, my bad, it was in "c:\tools\ES.exe"
And you're complaining about one typo *I* made ....
OUT.txt still looks different to you results, or did you edit the other stuff out?
No, of course not.
I think you have an echo on instead of an echo off.
That echo on was for debugging. It was not part of the steps to create a simple, equal test situation on both ends.

Could you post your current CMD script here? Makes it a lot easier to find out what's going on (instead of "searching in the dark")
Vortex
Posts: 11
Joined: Tue Aug 30, 2016 9:26 am

Re: CMD Search from list of partial filenames and copy matches?

Post by Vortex »

I ran this code on the actual file today:

Code: Select all

@echo off
:: SETTINGS
   set FOLDER=c:\temp
   set ES=c:\tools\everything\ES.exe
   set INPUT=IN.txt
   set OUTPUT=OUT.txt

::ACTION
   (for /f "usebackq tokens=1,2 delims=|" %%x in ("%INPUT%") DO "%ES%" -path "%FOLDER%" "%%x - %%y") > "%OUTPUT%"
pause
It found 17,617 matches out of the 120K lines.

I can manage the script to copy them to a folder myself.
Thanks for all your help :D
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: CMD Search from list of partial filenames and copy matches?

Post by NotNull »

Good luck!

Do yourself a favor; next time someone asks about your CMD experience (and I did because the title suggested you wanted a CMD solution), be honest about it. Most people don't have CMD experience; no big deal.
Now we ended up on different "wavelengths". Had I known you had no experience, I would have thought a minute longer and presented a 'waterproof' solution.


If you copy thàt much files to a single folder, you might run into limitations of the filesystem:
- FAT32 and older NTFS filesystem have a linit of 32k for a folder.
- Explorer used to get really sluggish with 5000+ files in a folder (haven't tried recently, so that might have changed)
- Your filesystem will probaly also create a short filename (8.3 notation). With that many files there might not be enough unique SFN's available.
Post Reply