Better way to find a folder and list contents?
Posted: 20 Aug 2016 14:38
Hi Folks -
I"m thinking about using the following script to locate a specific directory and then return it's contents:
It works, the display is a little cluttered:
Is there a way to add some code to just display *.BAK files? I'm open to making my code cleaner as well.
The reason I dont just set a variable for the fully qualified path to the \Backup directory is because the intermediary folders between Program Files & Backup can depending on server/version/installation. Hence why I search for \Backup.
Also, please note the string in red. I'm just recently seeing that. Does my script cause that error?
Thank you, all!
I"m thinking about using the following script to locate a specific directory and then return it's contents:
Code: Select all
set Dir=%ProgramFiles%\Microsoft SQL Server
cd %Dir%
for /d /r "%Dir%" %%a in (*) do if /i "%%~nxa"=="Backup" set "BKUP_PATH=%%a"
DIR "%BKUP_PATH%"
It works, the display is a little cluttered:
Volume in drive C has no label.
Volume Serial Number is DCFC-ECC3
Directory of C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup
08/20/2016 04:11 PM <DIR> .
08/20/2016 04:11 PM <DIR> ..
08/20/2016 04:11 PM 1,659,392 HYPDM_20160820.bak
1 File(s) 1,659,392 bytes
2 Dir(s) 57,911,906,304 bytes free
Is there a way to add some code to just display *.BAK files? I'm open to making my code cleaner as well.
The reason I dont just set a variable for the fully qualified path to the \Backup directory is because the intermediary folders between Program Files & Backup can depending on server/version/installation. Hence why I search for \Backup.
Also, please note the string in red. I'm just recently seeing that. Does my script cause that error?
Thank you, all!