You are not logged in.
I found your forum while researching a way to create a special directory listing. There were some pretty unique ideas in this forum that came very close to what I needed. I have tried modifying them with some success but still end up getting an output that needs modifications to be of use in the way I need it.
I manage a site that hosts a group of sub-sites made by various people. the entry to their sites includes 3w's.themastersite/theirname/theirsubsite.
with that directory list, I have a perfect list of access ports for each sub-site. VERY useful for organizing and making sure that all is correct.
What I need is a directory list that would show the full path from the top level to each sublevel and every sub-sub-level 4 levels deep beneath it. Just the directory names. no file names. I have tried various incantations of dir and gotten nowhere.
the first problem is that there is a "buffer" folder between the master site and the sub-sites called "webroot".
If I could run "DIR *. /S/4" while I was in the "3W's.mastersite.com" folder and get 3w's.mastersite.com/webroot/johndoe/site1, next line 3w's.mastersite.com/webroot/johndoe/site2, and so on.
the Johndoe would eventually change to marysmith, and all the rest of the people. the fictional "dir command" (as written) is what I would assume to be asking for directories only and 4 levels deep.
If anyone knows a way to accomplish this in a single run I would be ever so grateful. the DIR command wont do it. I have also tried a variation of the DU and the best I got at all was using powershell. I would gladly accept even having webroot left in as I can run a search and replace to get rid of it and the backward slashes. (which is part of what I am having to do now ) I have to run this list at least once a day and it gets tiring to say the least.
Offline
This works here:
@echo off
for /f "delims=" %%a in ('dir /ad /b /s ^| findstr \\.*\\.*\\.*\\.* ^| findstr /v \\.*\\.*\\.*\\.*\\') do echo %%a
pause
Offline
While I guess foxidrive's method could probably get the job done the problem would be that it will still parse the entire directory structure -- with web content that could be rather large.
I propose this alternative method:
@echo off
set "dir=X:\yourDirectory"
for /d %%a in ("%dir%\*") do (
for /d %%b in ("%%~a\*") do (
for /d %%c in ("%%~b\*") do (
for /d %%d in ("%%~c\*") do (
echo:"%%~d"
))))
goto :EOF
It's not very extensible or flexible, but should work fine. With a bit of work I think a variation on this method it could be made to select an arbitrary number of directory levels.
Last edited by bluesxman (19 Sep 2013 10:41)
cmd | *sh | ruby | chef
Offline
Actually, if you have robocopy (comes as standard with Vista and up; also available from Microsoft for anything older) you can do it like this:
robocopy /lev:4 /e /njh /njs /nc /ns /nfl /l X:\yourDirectory X:\not\a\real\directory
NB -- level "1" is the root of "yourDirectory" so you may need to increment the "/lev" switch by one to get the desired result.
cmd | *sh | ruby | chef
Offline
@echo off
rem DirLevel.bat - Antonio Perez Ayala
setlocal EnableDelayedExpansion
if "%1" neq "" goto begin
echo List directories up to a given level from current directory
echo/
echo DirLevel level
goto :eof
:begin
set "curDir=%cd%"
if "%curDir:~-1%" neq "\" set "curDir=%curDir%\"
set "lastName="
for /D /R %%a in (*) do (
set "dir=%%a"
set "dir=!dir:*%curDir%=!"
set level=0
set "name="
for %%b in ("!dir:\=" "!") do if "!level!" neq "%1" (
set name=!name!\%%~b
set /A level+=1
)
if "!name!" neq "!lastName!" (
echo %curDir%!name:~1!
set "lastName=!name!"
)
)
Antonio
Offline