How to? dir/pdir - 2nd level down only

Mar 17, 2013
11
0
Was a 4dos user way back in the early 90's and lost contact. Google reacquainted me and I'm back after a long journey....

This is about creating a directory listing to be used as a parse file for a restore script. I have millions of pictures already being backed up, and this is an attempt to create a restore system. The following allows me to repopulate the correct images back onto a workstation (D:) from the server (S:) should the workstation drive fail. Since there are 6 workstations all backing up to the server, I only want certain files restored. Namely files that were already on that workstation when it died. First I need to create the parse file from the workstation.

I need a directory listing (dir /s1 /b) of only the 2nd level directories for a backup application, logging the client files for a restore script that will do an xcopy from this list for restore purposes. Directory Structure is as follows:

Pix2012
Jan
Jan 1 Peter and Betty
Jan 15 Sally's Grad
Feb
Feb 4 Vacation
Feb 16 Dad's Birthday
Mar
Mar 14 Junky Pix

But in my output txt file, I get a separate line for Jan, Feb, and Mar that I don't want. How do I suppress the top level directories and only show the 2nd level and nothing below the 2nd level)

See a snippet of the actual output below (both dir and pdir were tried):

[S:\Pix2012]dir /s1 /b

S:\Pix2012\2012-01 Jan
S:\Pix2012\2012-02 Feb
S:\Pix2012\2012-03 Mar
S:\Pix2012\2012-07 Jul
S:\Pix2012\2012-10 Oct
S:\Pix2012\2012-12 Dec
S:\Pix2012\2012-01 Jan\[2012-01-03] PB Beauti, Marie
S:\Pix2012\2012-02 Feb\[2012-02-03] PB Grass, Paulette
S:\Pix2012\2012-03 Mar\[2012-03-03] PB Himly, Kara
S:\Pix2012\2012-07 Jul\[2012-07-03] PB Petersen, Corleen
S:\Pix2012\2012-10 Oct\[2012-10-05] PB Boyfox, Katey
S:\Pix2012\2012-12 Dec\[2012-12-05] PB Lennox, Sallie

If it just did a full restore by month, it would restore directories that I don't want restored. I only want the 6 listed.

Here is how it will work for a restore. The following will run in a cmd window and restore the directories parsed from the filelist.txt from S: back to D:

for /f "delims=" %%i in (filelist.txt) do echo D|xcopy "s:%%i" "d:%%i" /i /z /y /s

Here is where the idea comes from:

http://www.sidesofmarch.com/index.p...-command-to-copy-files-listed-in-a-text-file/
 
Aug 2, 2011
258
4
Berlin, Germany
If you just want to get the 2nd-level directories you could do it this way (q'n'd):
Example-directory structure:
Code:
S:\ >tree /a /s1
 
S:\
+--mib
|  \--netapp_mib2_1_3
+--Bilder
|  +--20080408
|  \--20090402
+--quotas
+--!Documentation
|  +--81rc1docs
|  +--802docs
|  +--NetApp OnCommand Core50docs
|  +--Unterlagen zu DOTF
|  \--Unterlagen zu DPR(DPS)
+--!Software
|  +--ESX Host Utilities
|  +--Firmware
|  \--Data ONTAP Powershell Toolkit
\--ndmpcopy
With DIR you get the top-level dirs that you don't want:
Code:
S:\ >dir /s1 /a:d /fh
S:\!Documentation
S:\!Software
S:\Bilder
S:\mib
S:\ndmpcopy
S:\quotas
S:\!Documentation\81rc1docs
S:\!Documentation\802docs
S:\!Documentation\NetApp OnCommand Core50docs
S:\!Documentation\Unterlagen zu DOTF
S:\!Documentation\Unterlagen zu DPR(DPS)
S:\!Software\Data ONTAP Powershell Toolkit
S:\!Software\ESX Host Utilities
S:\!Software\Firmware
S:\Bilder\20080408
S:\Bilder\20090402
S:\mib\netapp_mib2_1_3
If you filter all dirs with exactly two backslashes you get all 2nd-level directories:
Code:
S:\ >dir /s1 /a:d /fh | for %dir in (@con:) if %@index["%dir",\,0] EQ 2 echo %dir
S:\!Documentation\81rc1docs
S:\!Documentation\802docs
S:\!Documentation\NetApp OnCommand Core50docs
S:\!Documentation\Unterlagen zu DOTF
S:\!Documentation\Unterlagen zu DPR(DPS)
S:\!Software\Data ONTAP Powershell Toolkit
S:\!Software\ESX Host Utilities
S:\!Software\Firmware
S:\Bilder\20080408
S:\Bilder\20090402
S:\mib\netapp_mib2_1_3
I know, that's not very elegant but inflexible.
 
  • Like
Reactions: trad
Mar 17, 2013
11
0
If you just want to get the 2nd-level directories you could do it this way (q'n'd):
Example-directory structure:
Code:
If you filter all dirs with exactly two backslashes you get all 2nd-level directories:
[code]
S:\ >dir /s1 /a:d /fh | for %dir in (@con:) if %@index["%dir",\,0] EQ 2 echo %dir
I know, that's not very elegant but inflexible.

Looks like I will have problems with "&" in the file names. See this directory listing where it should be Jackson, Dave & Deanna:
Code:
S:\Pix2012\2012-03 Mar\[2012-03-08] Jackson, Dave
TCC: Unknown command "Deanna"
I also had to play with the /s1 and the EQ 2 as they seem to reference the entire tree, not from where you start on the tree but its workable...

Thanks
 
Aug 2, 2011
258
4
Berlin, Germany
Have a look at "SETDOS /X" to avoid &-problems.
 
  • Like
Reactions: trad
Aug 2, 2011
258
4
Berlin, Germany
This would be another way to do it:
Code:
>for /a:d /h %dir in (S:\*.*) ( do dir2 in /a:d "%dir"\*.* ( echo %dir2 ))
S:\mib\netapp_mib2_1_3
S:\Bilder\20080408
S:\Bilder\20090402
S:\!Documentation\81rc1docs
S:\!Documentation\802docs
S:\!Documentation\NetApp OnCommand Core50docs
S:\!Documentation\Unterlagen zu DOTF
S:\!Documentation\Unterlagen zu DPR(DPS)
S:\!Software\ESX Host Utilities
S:\!Software\Firmware
S:\!Software\Data ONTAP Powershell Toolkit
you can also specify a sub-directory of the tree:
Code:
\\osram.de\Net-BER\DV\Share >for /a:d /h %dir in (S:\!documentation\*.*) ( do dir2 in /a:d "%dir"\*.* ( echo %dir2 ))
S:\!documentation\81rc1docs\html
S:\!documentation\81rc1docs\meta-na
S:\!documentation\81rc1docs\pdfs
S:\!documentation\802docs\html
S:\!documentation\802docs\meta-na
S:\!documentation\802docs\pdfs
S:\!documentation\NetApp OnCommand Core50docs\html
S:\!documentation\NetApp OnCommand Core50docs\meta-na
S:\!documentation\NetApp OnCommand Core50docs\pdfs
S:\!documentation\Unterlagen zu DOTF\MASK
 
Apr 2, 2011
1,441
10
54
North Carolina, USA
global /i /q /h for /a:d %dir1 in (*) do for /a:d %dir2 in ("%dir1\*") do echo %dir2

will also work..... Or am I missing soemthing...?
 
Similar threads
Thread starter Title Forum Replies Date
S WAD /Sn mishandled in DIR and PDIR, possibly elsewhere Support 15
M A simple question related to the "dir" (and "pdir") commands... Support 5
E Fixed Bug with DIR /Z displaying descriptions Support 8
J Paths shown in DIR /B Support 2
K Fixed Prompt display will be shifted after use dir to display a filename with Chinese. (v25.00.28 x64) Support 18
Jesse Heines How to? How to display picture creation date with dir command Support 6
vefatica WAD DIR.BTM? Support 11
DrusTheAxe DIR reports meaningless SYMLINK information Support 14
C show file description? with dir? Support 8
vefatica DIR /F and streams? Support 7
rps Multi-column DIR /v not displaying all files. Support 5
R How to? Dir specific file search patterns with spaces in the pathnames? Support 6
rps Dir /Nfv -> Alt-F2 Support 2
rps @FILESIZE[....,a] allocated size not matching Dir results Support 8
A TCMD - Dir Command puts out blank lines? Support 16
S Problems with dir command in the debugger Support 5
M TCC incorrect dir output since Windows 1803 Support 6
x13 Problem listing repository files using DIR http(s)://... Support 8
cxxl dir /s works in mysterious ways :( Support 4
vefatica Help nit (FFIND and DIR with /S) Support 0
N Fixed Strange dir behavior Support 6
JohnQSmith Weird DIR output (missing lines) Support 1
C 7zip with date range .vs. filelist created with dir and daterange Support 0
D Towards shared (dir-)history lists Support 3
vefatica WAD DIR /HL still gets names wrong Support 16
vefatica DIR /S /HL? Support 4
H Fixed DIR /G returns wrong sizes Support 2
nickles WAD dir.htm Support 2
vefatica DO dir in /s /a:+d /d"g:\" * ( ... ) Support 26
vefatica DIR \\.\...? Support 4
M Fixed DIR /S /B1 ignores "/S" Support 5
C tcmd.ini not loading from program dir? Support 5
D Fixed Dir /Nm:n has changed Support 1
rps How to? dir /s unexpected results Support 10
vefatica Update to current install dir? Support 8
cgunhouse Problem with "dir /=" Support 4
T dir /h error in empty directory Support 22
P WAD TC 15.0.1.58 x64 crasches with a simple dir command Support 18
CWBillow dir /4 strange Support 2
samintz WAD DIR /B1 and /X Support 2
nickles dir behaves inconsistently Support 5
vefatica DIR, streams, and wildcards? Support 1
vefatica DIR /: /u ... streams not counted? Support 7
vefatica Documentation DIR /B /S /: Support 2
samintz How to? DIR listing for exact match Support 1
dcantor WAD dir "ftp:// ..." fails in TCC 15 Support 7
MikeBaas How to? DIR: supress extensions? Support 5
old coot dir /s dies on my C: drive Support 2
A WAD Dir daterange + multiple path wildcards crashes tcc Support 2
old coot TC DIR command has trouble on my SSD Support 2

Similar threads