Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

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

Mar
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/
 
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.
 
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
 
Have a look at "SETDOS /X" to avoid &-problems.
 
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
 
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

Back
Top