Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Thursday, January 14, 2010

Relative Directory Listing Batch Script

I needed to recreate a directory structure elsewhere, so the first step was to get it from the source. I only wanted directories, but you can get a full file listing by modifying two characters in this script (see comments).

Original script borrowed from http://forums.techguy.org/windows-vista/741144-dir-command-help.html and findstr information from http://technet.microsoft.com/en-us/library/bb490907.aspx


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::RDIR -- Relative Directory listing
::Type RDIR /? for usage info
::Written by TheOutcaste 08/18/2008 for TechSupportGuy forum
::http://forums.techguy.org
::MODIFIED by Peter Vieth 01/14/2010 - lists ONLY directories, ignores .svn dirs (see comments)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@Echo Off
If [%1]==[/?] GoTo Usage
If [%1]==[-?] GoTo Usage
Setlocal EnableDelayedExpansion
If [%1]==[] goto Main
set _tmp=%1
If /I %_tmp:~0,3%==%CD:~0,3% GoTo Error
If /I %_tmp:~0,3%==..\ GoTo Error

:Main
rem B:bare
rem AD: list dir only
rem S: recursive
rem on:???
rem ^| findstr /v /i "\.svn" : excludes anything containing svn (^ is escape character, v prints lines that dont match, \. escapes .)
Set _t0=1
If ["%CD%"]==["%CD:~0,3%"] Set _t0=0
For /F "tokens=*" %%A In ('DIR "%*" /B /AD /on /S ^| findstr /v /i "\.svn"') Do (
Set _t1=%%A
Set _t2=!_t1:%CD%=!
Echo !_t2:~%_t0%!
)
Endlocal
goto:EOF

:Error
Echo.
Echo.Error - Drive letter or parent folder was specified.
Echo. You must specify only subfolders of the current folder
Echo.

:Usage
Echo.USAGE:
Echo.Generates a Directory listing in bare format relative to the current Folder
Echo.
Echo.RDIR [subfolder]
Echo.
Echo. subfolder Name of the subfolder of the current folder that you wish
Echo. to list. If not specified, lists the current folder and it's
Echo. subfolders
HTH

Monday, May 18, 2009

Recursive File Listing

Here's how to create a recursive file listing in Windows from the command shell:
dir /a /s /-p /b /o:gen *.cdg > filelisting.txt

Check out this link for adding it to the context menu.

Labels

Blog Archive

Contributors