Batch file to list directories, export to CSV
Good morning:
A while ago I had a batch file I put together with a little help from
some tutorials to scan through a list of directories kept in a
separate TXT file, echo the size of each directory on the screen, and
also echo them out to a CSV file (DIRECTORY,SIZEinBYTES). I'm using
it to do a quick poll of the size of users personal folders on our
network share, so first it would map the root of the shar drive as Z:
\, then it would go through each one in the list I created and give
the size of all the data contained in that directory.
Can anyone point me to a website with this code? I've been on Google
all morning but can't find the website I used.
Re: Batch file to list directories, export to CSV
On Feb 16, 9:50 am, chickenfriedsteak <ow...@chickenfriedsteak.us>
wrote:
> Good morning:
>
> A while ago I had a batch file I put together with a little help from
> some tutorials to scan through a list of directories kept in a
> separate TXT file, echo the size of each directory on the screen, and
> also echo them out to a CSV file (DIRECTORY,SIZEinBYTES). I'm using
> it to do a quick poll of the size of users personal folders on our
> network share, so first it would map the root of the shar drive as Z:
> \, then it would go through each one in the list I created and give
> the size of all the data contained in that directory.
>
> Can anyone point me to a website with this code? I've been on Google
> all morning but can't find the website I used.
Just a minute after I posted this, I found what I was looking for.
For anyone interested:
@echo off
set servlist=c:\serverlist.txt
if not exist %servlist% echo %servlist% not found & pause & goto end
set listfile=c:\dirsize.csv
for /f "tokens=*" %%a in (%servlist%) do call :process %%a
goto end
:process
for /f "tokens=3" %%x in ('dir %1 /-c/s ^| find "File(s)"') do set
total=%%x
echo %1, %total%
echo %1, %total% >> %listfile%
:end