Recursive Searching Across Directories & Date Sorting

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Recursive Searching Across Directories & Date Sorting

#16 Post by atfon » 09 Oct 2017 08:03

The issue I was seeing with Robocopy was due to it encountering a Junction or Symbolic Link in the Users folder. If I use the /XJ parameter, these are ignored.

/xj Excludes junction points, which are normally included by default.

https://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: Recursive Searching Across Directories & Date Sorting

#17 Post by Compo » 09 Oct 2017 09:26

I still think that with the addition of those options, '/W:0', '/R:0' and either '/XJ' or '/XJF' with '/XJD', you'll still get permission errors on the system drive!

Did you try the non-localised WMIC solution I provided?

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Recursive Searching Across Directories & Date Sorting

#18 Post by atfon » 09 Oct 2017 10:14

This worked like a charm from the root of the hard drive:

robocopy "\." "\." *.txt /l /s /is /ts /ndl /njh /njs /nc /ns /xj /R:0 /W:0

No errors were received. It was faster than the WMIC solutions and did not require administrative rights.

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: Recursive Searching Across Directories & Date Sorting

#19 Post by Compo » 09 Oct 2017 11:03

Well it may work for you, but it doesn't for me, as I said, you will still receive "Access is denied" messages. Unless of course you run it As administrator, which isn't necessary with my WMIC solution.

On a brand new fully updated Windows 7 Pro installation with no programs installed I just received 67 such messages

By the time I've removed those from the output, which I would have to do before sorting, by piping it to findstr:

Code: Select all

|FindStr/IVC:"0x00000005" /C:"Access is denied"

The method will not be noticeably quicker than my WMIC solution and the "Access is denied" string would be language dependent!

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Recursive Searching Across Directories & Date Sorting

#20 Post by atfon » 09 Oct 2017 11:30

According to this site, running WMIC requires Administrative rights:

https://ss64.com/nt/wmic.html

I attempted your WMIC command on a Windows 7 Pro system with Admin rights, but it produced an empty output file.

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Recursive Searching Across Directories & Date Sorting

#21 Post by atfon » 09 Oct 2017 11:44

I was able to get Compo's WMIC script to work, so that is a possibility. It just does not provide the date in as readable a format as the robocopy option. I will do some further experimentation to see which is the most viable option for the environments involved.

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: Recursive Searching Across Directories & Date Sorting

#22 Post by Compo » 09 Oct 2017 11:57

You need to compromise, either have it readable by someone who hasn't learned to read it properly but can run it without Administrator privileges or use your method As administrator and sort the files according to narrower parameters.

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Recursive Searching Across Directories & Date Sorting

#23 Post by atfon » 09 Oct 2017 13:02

You need to compromise


Understood. For what it's worth, I also tested this successfully on a system that did not have Administrative rights automatically invoked for the command line:

Code: Select all

for /f "tokens=*" %%a in ('robocopy "\." "\." *.txt /l /s /is /ts /ndl /njh /njs /nc /ns /xj /R:0 /W:0 ^| sort /r') do echo %%a >> %userprofile%\Desktop\Text_Files.txt


As I mentioned, I will continue to investigate the solutions that will work best in my environments.

Thanks to everyone for their time and input.

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: Recursive Searching Across Directories & Date Sorting

#24 Post by Compo » 10 Oct 2017 06:47

Just to provide you with the 67 errors from your robocopy command above when not run as administrator:

Code: Select all

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\$Recycle.Bin\S-1-5-21-██████████-█████████-█████████-500\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\$Recycle.Bin\S-1-5-21-█████████-██████████-██████████-500\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\$Recycle.Bin\S-1-5-21-███████-██████████-█████████-500\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\$Recycle.Bin\S-1-5-21-█████████-██████████-██████████-500\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\PerfLogs\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Crypto\PCPKSP\WindowsAIK\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Crypto\RSA\S-1-5-18\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Diagnosis\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\NetFramework\BreadcrumbStore\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Network\Downloader\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Search\Data\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\Power Efficiency Diagnostics\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_mscorsvw.exe_f89c3fda3fcca1d3b5a54535c52e859f365ee6c2_cab_0763e3de\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_NvNetworkService_75bf4b7863cdee8909e2489861548c577eee9b_cab_0a4be4c8\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\Critical_6.1.7601.17514_152a144e1eee6d1b77a13392b29820e0ad566681_cab_062e2e06\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\Critical_6.1.7601.17514_4f2fe9e78cf7a355e6c2321ff4a738048fe3bf_cab_07c8482a\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\Critical_6.1.7601.17514_8ccac6e68f82f4ff95fe577a136de94e58e535_cab_08051a38\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\Critical_6.1.7601.17514_b8865c20c23f9ffe5c2e093928eaf83b8da088_cab_0efd4666\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_7.6.7600.320_8a471a6b2dff5c0b1d5abb21dc792e26ca5e48_cab_0c4a4868\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_7.6.7600.320_8b89378b89bc5e4e35b54fdc84eafebd7783a1a9_cab_00b06413\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_7.6.7600.320_9419bb7da922f63bd6d64875c85dc773b31dc4d8_cab_0dc14119\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_7.6.7600.320_feace469d499e4bbe372a446481e6253c129938a_cab_067d786e\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_x64_24644b26f8affe8afd2637c732fa088a7473ff9_cab_066070db\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_x64_476796c0a6aeeabf14a29e151477e45df5a4a343_cab_06e966fc\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_x64_5ebd4f51d6f72ab05e8e31e84dcf68f363693678_cab_06294b32\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_x64_84c3618b63b11ff7409d93dc294f7aac796b1b4_cab_079d7a0f\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_x64_b0e3107c51db894dd520e46d658c3680ebc16de9_cab_0631389c\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_x64_b4c832d2a4acb55a56e4ae4feb3c71579e495ef_cab_07dcef1e\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows\WER\ReportQueue\NonCritical_x64_ee8c9577879c6217a2817e22f26e1a228a5b_cab_076d6b01\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows Defender\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\Microsoft\Windows NT\MSFax\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\ProgramData\NVIDIA Corporation\NvTelemetry\reports\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\Recovery\
Access is denied.

2017/10/10 13:17:04 ERROR 5 (0x00000005) Scanning Source Directory C:\System Volume Information\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\AppCompat\Programs\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\CSC\v2.0.6\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\LiveKernelReports\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\Logs\HomeGroup\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\Logs\SystemRestore\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\ModemLogs\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\PLA\Reports\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\PLA\Rules\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\PLA\Templates\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\Prefetch\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\security\audit\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\ServiceProfiles\LocalService\
Access is denied.

2017/10/10 13:17:05 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\ServiceProfiles\NetworkService\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\com\dmp\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\config\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\ias\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\LogFiles\Fax\Incoming\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\LogFiles\Fax\Outgoing\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\LogFiles\Firewall\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\LogFiles\WMI\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\Msdtc\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\NetworkList\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\spool\PRINTERS\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\Tasks\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\wbem\MOF\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\wdi\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\System32\wfp\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\SysWOW64\com\dmp\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\SysWOW64\config\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\SysWOW64\Msdtc\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\SysWOW64\NetworkList\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\SysWOW64\Tasks\
Access is denied.

2017/10/10 13:17:07 ERROR 5 (0x00000005) Scanning Source Directory C:\Windows\Temp\
Access is denied.
This was run by a member of the Administrators group in a standard cmd.exe session under Windows 7 x64 Professional fully updated but without absolutely no settings changes, (UAC is on), and no OEM or additional software installed.

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Recursive Searching Across Directories & Date Sorting

#25 Post by atfon » 10 Oct 2017 07:02

The robocopy ran quickly for me in both an Admin and non-Admin scenario and produced the output that I need. I can invoke an option in the script that if it is being run without Admin rights, to just use the dir option to capture the non-sorted data.

And WMIC is going to require local Admin rights to run properly too, according to what I've read:

https://www.itworld.com/article/2815043/operating-systems/windows-tip--wmic-and-non-admins.html

I thank you for all your time and effort. I believe I understand now what can and cannot be done with this from a batch script. I may attempt a non-Batch solution down the line, but this works for now.

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: Recursive Searching Across Directories & Date Sorting

#26 Post by Compo » 10 Oct 2017 17:38

Is there a particular reason why you're steadfast in this. It is a known unarguable fact that a normal Administrator's group user on a modern PC is restricted from certain parts of the OS for security reasons. Now only if your task was to search system protected files would it be worth bypassing those protections. Your question and subsequent responses have not stipulated that.

atfon wrote:And WMIC is going to require local Admin rights to run properly too, according to what I've read:
I'm not trying to trick you into something, if the WMIC version I posted had needed to be run As administrator, do you not think I'd have said so, or be pushing this particular point. You need to understand that since Vista and it's accompanying User Account Control, that a normal user (allocated an Administrator account), does not have the same level of privilege of As Administrator. There may be reasons why a Standard user account holder could have issues with it, but I'd never attempt to ask, or would never expect a Standard user to run this type of script.

The WMIC script by the way has just been tested untouched on an Administrator group account on Windows Vista Home Premium with Service Pack 2 without being run As administrator. It worked flawlessly, (even removing the additional filters only provided me 3 more files).

I'm not saying that there's anything wrong with pursuing your goal, just that sometimes it really isn't worth it. Especially when the only benefits would be a couple of seconds and perhaps listing some protected files which should be untouched anyhow because of those protections.

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Recursive Searching Across Directories & Date Sorting

#27 Post by atfon » 11 Oct 2017 08:36

WMIC documentation is incredibly sparse. I have seen how you can convert from UNICODE to ANSI and remove the extra <CR> in the output. I am still struggling with parsing the output to get the results I need. I realize you are very attached to this solution and it may indeed be the optimum solution in batch.

Post Reply