DIR of only specific levels
Moderator: DosItHelp
DIR of only specific levels
I am trying to get a list of all of the "project.ini" files in a directory on our network. The problem is that all of these files are only 1 or 2 levels deep in that directory, so when i run: "dir /a-d /s /b M:\Cases\*Project.ini > DIR.txt" - it works, but might take all day. There are thousands of folders and millions of files within that directory.
Is there a way to limit how many folders deep it looks? I need it to look up to 2 folders deep, but not any further than that.
Thanks in advance for any help..
Is there a way to limit how many folders deep it looks? I need it to look up to 2 folders deep, but not any further than that.
Thanks in advance for any help..
Re: DIR of only specific levels
There is no built in method to only search 2 levels deep, you will have to list the directories at least
- to then check for that file in the two levels.
EDIT: The above is not true for all methods, but does apply when using the command in the example above of
"dir /a-d /s /b M:\Cases\*Project.ini > DIR.txt"
Is this over a LAN? You mentioned network.
- to then check for that file in the two levels.
EDIT: The above is not true for all methods, but does apply when using the command in the example above of
"dir /a-d /s /b M:\Cases\*Project.ini > DIR.txt"
Is this over a LAN? You mentioned network.
Re: DIR of only specific levels
Yes. Over a LAN in an office environment.
Re: DIR of only specific levels
Inside the "M:\Cases\" folder I am working with, there are 1,200+ folders that each contain a "project.ini" file (at that level, or one level further in). I just need a list of the files that exist.
Inside those 1,200+ folders there are thousands of sub-folders which is why I have an issue with this taking too long to scan and list what I need.
Inside those 1,200+ folders there are thousands of sub-folders which is why I have an issue with this taking too long to scan and list what I need.
Re: DIR of only specific levels
Try this:
Antonio
Code: Select all
@echo off
(for /D %%a in (M:\Cases\*) do (
dir /B %%a\Project.ini 2> NUL
for /D %%b in ("%%a") do dir /B "%%b\Project.ini" 2> NUL
)) > DIR.txt
Antonio
Re: DIR of only specific levels
That lists most of the folders, but not all of them. There are some folders that do not have the "project.ini" file in there, but I checked, and some that do have the INI file were not listed in the output from your script.
It did run very quickly, so I am guessing it did limit the scan to 2 levels of recursion...
Getting closer!
It did run very quickly, so I am guessing it did limit the scan to 2 levels of recursion...
Getting closer!
Re: DIR of only specific levels
After i have tried reading out of your mind via internet which folders were not listed, but do have the "project.ini" file in there (just joking),
i guess you need more than 2 levels of recursion (probably 3 levels).
If i am wrong, please provide more information.
penpen.
i guess you need more than 2 levels of recursion (probably 3 levels).
If i am wrong, please provide more information.
penpen.
Re: DIR of only specific levels
jugrugs wrote:That lists most of the folders, but not all of them. There are some folders that do not have the "project.ini" file in there, but I checked, and some that do have the INI file were not listed in the output from your script.
It did run very quickly, so I am guessing it did limit the scan to 2 levels of recursion...
Getting closer!
Please, read this post in first place.
My solution was written assuming a directory with a structure similar to this one:
Code: Select all
M:\Cases\one\Project.ini
M:\Cases\one\A\Project.ini
M:\Cases\one\A\ABC\Project.ini
M:\Cases\one\A\ABC\XYZ\Project.ini
M:\Cases\one\B
M:\Cases\one\C\Project.ini
M:\Cases\two\A
M:\Cases\two\B\Project.ini
M:\Cases\two\C
M:\Cases\two\D\Project.ini
...
M:\Cases\oneThousandTwoHundred\Project.ini
M:\Cases\oneThousandTwoHundred\A
M:\Cases\oneThousandTwoHundred\A\XYZ\Project.ini
M:\Cases\oneThousandTwoHundred\B\Project.ini
Given previous structure, the program should produce this result:
Code: Select all
M:\Cases\one\Project.ini
M:\Cases\one\A\Project.ini
M:\Cases\one\C\Project.ini
M:\Cases\two\B\Project.ini
M:\Cases\two\D\Project.ini
...
M:\Cases\oneThousandTwoHundred\Project.ini
M:\Cases\oneThousandTwoHundred\B\Project.ini
That is, "Inside the "M:\Cases\" folder there are 1,200+ folders that each contain a "project.ini" file (at that level, or one level further in). I just need a list of the files that exist" as requested.
You are suggesting that some existent files in previous structure were missed from the DIR /B command? It is very unlikely that this may happen (to not said "impossible"). A program always run as it was programmed, there is not such "Getting closer!" thing...
The point that really confuses me is that you first said "all of these files are only 1 or 2 levels deep in that directory", "I need it to look up to 2 folders deep, but not any further than that", but in your last reply you said "It did run very quickly, so I am guessing it did limit the scan to 2 levels of recursion..." ???
Now, read again the recommendations at the link above and post a reply with full details...
Antonio
Re: DIR of only specific levels
The results I got from your script gave me this output:
Folder1
Folder2
Folder3
Project.ini
Folder4
Folder5
Folder6
Folder...
It listed tons of the folders (but not all of them), and it did not list them as a full path output with the filename appended like you suggest it should. It only listed 4 project.ini files total (of 2,400+ lines of output) and they were listed by themselves, so I didn't know what folder they belonged to.
I was able to get the results I needed using a robocopy level command.
Thank you very much for your time!
Folder1
Folder2
Folder3
Project.ini
Folder4
Folder5
Folder6
Folder...
It listed tons of the folders (but not all of them), and it did not list them as a full path output with the filename appended like you suggest it should. It only listed 4 project.ini files total (of 2,400+ lines of output) and they were listed by themselves, so I didn't know what folder they belonged to.
I was able to get the results I needed using a robocopy level command.
Thank you very much for your time!
Re: DIR of only specific levels
…yep something like this:
Code: Select all
ROBOCOPY M:\Cases M: *Project.ini /LEV:2 /S /FP /L /NS /NC /NDL /NJH /NJS /LOG:Dir.txt
Re: DIR of only specific levels
Yessir. Actually, yours is the simple version I was looking for. Thanks!!
I got it to work using:
Thank you everyone for the help!
I got it to work using:
Code: Select all
@echo off
SetLocal
:: script name with extension
SET BAT_NAMEX=%~nx0
:: script name without extension
SET BAT_NAME=%~n0
TITLE %BAT_NAMEX%
:: prepare date/time stamp
FOR /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%i-%%j-%%k-%%l
FOR /f "Tokens=1-2" %%i in ('time /t') do set tm=-%%i-%%j
:: timestamp (dd-mm-yyyy-hh-mm-am)
SET TM=%tm::=-%
SET DTS=%dt%%tm%
::## Set Paths List
SET PATHS_LIST=%BAT_NAME%.list
::## Set Log File
SET LOG_FILE=T:\Project-ini\%BAT_NAME%_%DTS%.log
:: start Robocopying
echo -----
FOR /F "usebackq tokens=1 delims=||" %%a in ("%PATHS_LIST%") DO (
Robocopy.exe "%%a" "%%a" project.ini /nc /nfl /njh /njs /l /e /np /lev:4 /tee /r:3 /log+:"%LOG_FILE%"
echo(
echo -----
)
echo %BAT_NAMEX% has finished...
EndLocal
Thank you everyone for the help!
Last edited by jugrugs on 26 Mar 2015 10:57, edited 1 time in total.
Re: DIR of only specific levels
I don't think you can use the same source and destination; and since you're already hard coding a location in T: there's no reason why you cannot use "%%~a" T:jugrugs wrote:FOR /F "usebackq tokens=1 delims=||" %%a in ("%PATHS_LIST%") DO (
Robocopy.exe "%%a" "%%a" project.ini /nc /nfl /njh /njs /l /e /np /lev:4 /tee /r:3 /log+:"%LOG_FILE%"
echo(
echo -----
)
Re: DIR of only specific levels
Someone gave me that code, so I'm not sure why it is like that - but it worked. I had to manipulate the output log afterward for what I needed from it though, so the simpler version is much better.
Re: DIR of only specific levels
With a tweak and change of tactic - the code below shows the following:
"d:\abc\aaa\Project.ini"
"d:\abc\aaa\bbb\Project.ini"
"d:\abc\backup\123\Project.ini"
When these files are present:
(however files like "project.init" and "project.ini-four" in the first two levels will confuse it)
d:\abc\project.ini
d:\abc\aaa\project.ini
d:\abc\aaa\bbb\project.ini
d:\abc\aaa\bbb\222\project.ini
d:\abc\aaa\bbb\222\ccc & ddd\project.ini
d:\abc\aaa\bbb\222\ccc & ddd\eee\project.ini
d:\abc\backup\123\project.ini
d:\abc\backup\123\bbb\project.ini
d:\abc\backup\123\bbb\ccc & ddd\project.ini
d:\abc\backup\123\bbb\ccc & ddd\eee\project.ini
"d:\abc\aaa\Project.ini"
"d:\abc\aaa\bbb\Project.ini"
"d:\abc\backup\123\Project.ini"
When these files are present:
(however files like "project.init" and "project.ini-four" in the first two levels will confuse it)
d:\abc\project.ini
d:\abc\aaa\project.ini
d:\abc\aaa\bbb\project.ini
d:\abc\aaa\bbb\222\project.ini
d:\abc\aaa\bbb\222\ccc & ddd\project.ini
d:\abc\aaa\bbb\222\ccc & ddd\eee\project.ini
d:\abc\backup\123\project.ini
d:\abc\backup\123\bbb\project.ini
d:\abc\backup\123\bbb\ccc & ddd\project.ini
d:\abc\backup\123\bbb\ccc & ddd\eee\project.ini
Code: Select all
@echo off
(for /D %%a in (d:\abc\*) do (
for %%b in ("%%a\Project.ini?") do echo("%%a\Project.ini"
for /D %%c in ("%%a\*") do for %%b in ("%%c\Project.ini?") do echo("%%c\Project.ini"
)) > DIR.txt
Re: DIR of only specific levels
foxidrive;
That is pretty awesome. That worked great too (as well as the robocopy options). I just don't understand how.
The literal script I used is:
If I may ask-
What do the "%%a", "%%b" & "%%c" commands do?
Also, why "for /D"?
Sorry for my ignorance, but I am a novice.
That is pretty awesome. That worked great too (as well as the robocopy options). I just don't understand how.
The literal script I used is:
Code: Select all
@echo off
(for /D %%a in (M:\CASES\*) do (
for %%b in ("%%a\Project.ini?") do echo("%%a\Project.ini"
for /D %%c in ("%%a\*") do for %%b in ("%%c\Project.ini?") do echo("%%c\Project.ini"
)) > DIR.txt
If I may ask-
What do the "%%a", "%%b" & "%%c" commands do?
Also, why "for /D"?
Sorry for my ignorance, but I am a novice.