maximus1974
asked on
Need help modifying a script to help search for files with specific values in names
Need help modifying this following script where it will search for files within \\NTAPP\E containing the values specified in the text file attached.
Ex. *24558*, PO 24558, PO 24558-1A
Search the whole E drive for files containing 24558 specifically in this order.
I want the script to search for all 19000+ files within the text file at the same time and copy them to the destination specified below.
I was tasked to find scanned documentation for all the PO's specified in the text file. They can be anywhere within the E drive.
Ex. *24558*, PO 24558, PO 24558-1A
Search the whole E drive for files containing 24558 specifically in this order.
I want the script to search for all 19000+ files within the text file at the same time and copy them to the destination specified below.
I was tasked to find scanned documentation for all the PO's specified in the text file. They can be anywhere within the E drive.
set src_folder=\\ntapp\E
set dst_folder=C:\PO_CARLOS
for /f %%i in (C:\PO_CARLOS\PO_CARLOS.txt) DO copy "%src_folder%\%%i" "%dst_folder%\%%i"
ASKER
How would I use strings to search for 19000+ PO numbers at the same time? not just one "24558".
If you do not want to exclude any use
strings -s * | findstr /r "PO[0-9][0-9][0-9][0-9][0-9]"
ASKER
NO. I want to search for specific PO numbers such as the ones listed in the text file. I need to find 19000+ PO scans on the Server. The files will contain the PO number in the name.
If the PO is in name
Copy column B and past it in CMD to run it
After execution Report.txt will have all the files
DIR *24558* /s/a/b >> Report.txt
Then you build the commands in Excel for example="DIR *" & A1 & "* /s/a/b >> Report.txt"
="DIR *" & A2 & "* /s/a/b >> Report.txt"
="DIR *" & A3 & "* /s/a/b >> Report.txt"
...
="DIR *" & A19000+ & "* /s/a/b >> Report.txt"
where the POs are in Column A and formula in Column BCopy column B and past it in CMD to run it
After execution Report.txt will have all the files
You can use report.txt to copy files
Only saw copy now. Working on better solution
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And if you do not want folder structure use this on line 10
forfiles /p %src_folder% /m *%~1*.* /s /c "cmd /c copy @path %dst_folder%
ASKER
Regarding replacing line 10, you mean removing "robocopy %src_folder% %dst_folder% *%~1*.* /E" and replacing it with "forfiles /p %src_folder% /m *%~1*.* /s /c "cmd /c copy @path %dst_folder%"?
Yes, but only if you do not want the folder structure to be replicated. The forfiles command will put all files in same folder (flat)
ASKER
Thank you. I am receiving this error when running the script: ERROR: the filename or extension is too long.
This is the script I am using:
This is the script I am using:
set src_folder=U:\
set dst_folder=C:\PO_CARLOS
for /f %%i in (C:\PO_CARLOS\PO_CARLOS.txt) DO call:SearchAndCopy %%i
Goto END
:SearchAndCopy
forfiles /p %src_folder% /m *%~1*.* /s /c "cmd /c copy @path %dst_folde
:END
Do you get it with robocopy too?
ASKER
No error when using robocopy.
1. Is the PO number part of the name of the file or a string inside the file?
2. Please post some representative examples of the lines in PO_CARLOS.txt file
2. Please post some representative examples of the lines in PO_CARLOS.txt file
You are running into Windows limitation. Perhaps stick with Robocopy if you can live with folders
@ECHO OFF
set src_folder=\\ntapp\E
set dst_folder=C:\PO_CARLOS
for /f %%i in (C:\PO_CARLOS\PO_CARLOS.txt) DO call:SearchAndCopy %%i
Goto END
:SearchAndCopy
xcopy "%src_folder%\*%~1*" "%dst_folder%" /s /y
:END
ASKER
The PO number is a string inside the file name.
Here are some examples of the PO's:
2208131
2208131
2156692
2156692
80936
2165357
2127827
2153413
2168602
2168602
2126096
2104060
21883932
2185926
2148058
2148058
2053383
2119262
71965
2129521
2198632
16948
16948
3204404
Here are some examples of the PO's:
2208131
2208131
2156692
2156692
80936
2165357
2127827
2153413
2168602
2168602
2126096
2104060
21883932
2185926
2148058
2148058
2053383
2119262
71965
2129521
2198632
16948
16948
3204404
ASKER
Shaun, when I use the latest script you provided using xcopy, the command prompt window just stays black and does nothing. Also, when I use Robocopy, it copies empty folders, containing no files.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can run Robocopy with switch settings that will just list what it would do without actually doing any copying or moving.
Do you have to watch out for false positives, where the file name contains the matching string and then some non-matching text?
Download strings.exe from https://technet.microsoft.com/en-us/sysinternals/strings.aspx
Open in new window