Create a file list from multiple folders

February 20, 2010 at 08:50:15
Specs: Windows XP
Hi,

I have two folders( for now) which contain almost 500 files. I want to create a list of files from these folders and sort them in alphabetical order and give a total count at the last. If possible can I have even the path location of each file. Is this possible with context menu?


Any help is appreciated.

Thanks


See More: Create a file list from multiple folders

Report •


#1
February 20, 2010 at 09:48:05
Tailor the folder names to suit.

============================
@echo off & setLocal EnableDELAYedeXpansion

set N=

for /f "tokens=* delims= " %%a in ('dir/s/b/a-d \temp \files') do (
>> newfile echo %%~Fa
set /a N+=1
)
sort < newfile > sorted
echo total is !N! ; result is in sorted


=====================================
Helping others achieve escape felicity

M2


Report •

#2
February 20, 2010 at 11:14:48
Thanks for the reply.

Its just a doubt. Why we are parsing the file list through" tokens"
and "delimit" options. And what "set /a" command does


Report •

#3
February 20, 2010 at 11:33:10
I wrote the script in a batch file and placed in windows folder
and created a context menu action for the batch file.
I tried on three selected folders at once. I had modified the file
names in the batch file. But I donot know where is the file is
located now? and its contents.

==============================
@echo off & setLocal EnableDELAYedeXpansion
set N=
for /f "tokens=* delims= " %%a in ('dir/s/b/a-d \temp \files') do
(
>> C:\Documents and Settings\Chanikya\Desktop\filelist.txt
echo %%~Fa
set /a N+=1
)
sort < C:\Documents and
Settings\Chanikya\Desktop\filelist.txt > C:\Documents and
Settings\Chanikya\Desktop\sortedfilelist.txt
echo total is !N! ; result is in sorted

==========================


Report •

Related Solutions

#4
February 20, 2010 at 12:00:34
To use a path with spaces you need double quotes.

"C:\Documents and Settings\Chanikya\Desktop\filelist.txt"

It would be far simpler to just change to that directory.


=====================================
Helping others achieve escape felicity

M2


Report •

#5
February 20, 2010 at 12:40:44
Sorry, just forgot basic syntax

Report •

#6
February 20, 2010 at 13:21:24
The below may als work. Note that it displays and counts all files (in all subdirectories) ... not sure that is what you want. The problem is that when you omit the /S parameter, the /B parameter reacts to that and shows only the name of the file, not the path.

@echo off

set result=C:\result.log

dir C:\windows c:\progra~1 /B /S /A-D | sort > %result%
dir C:\windows c:\progra~1 /B /S /A-D | find /C "\" >> %result%


Report •

#7
February 26, 2010 at 14:01:52
I got the point but the folders I am searching is arbitrary. So
the folder locations if inserted in batch file then it only looks
for that specific folder but not other folders which I may want
in future.

Actually one of my friend wrote the batch file like this....
==============
cd %1
dir /a/b/-p/o:gen > filelist.txt
copy filelist.txt "C:\Documents and
Settings\Chanikya\Desktop"
del filelist.txt
=============

This batch file I am accessing through context menu so the
file contains folder list in the filelist.txt file. Here it is not
getting the path of the file and also it deleting the old file. Hoe
to append the existing file I donot know while I use copy
command. Then the problem comes is sorting.

Thanks in advance


Report •

#8
February 27, 2010 at 04:39:42
I'm assuming you want the sort in the result of the DIR command, and THEN add that to the existing filelist.txt

If you want the filelist.txt to be sorted AFTER you add the result from the curent DIR command, you need to do something else.

You can call :
<script>.cmd c:\windows
<script>.cmd "C:\documents and settings"

@echo on

if -%1==- goto :EOF

set varpath=%1

dir %varpath% /a/b/-p/o:gen | sort >> "C:\Documents and Settings\%username%\Desktop\filelist.txt"


Report •

#9
February 27, 2010 at 07:31:58
I don't know what you're trying to do with this, but I'll stay tuned.

---------------------
/a/b/-p/o:gen


=====================================
Helping others achieve escape felicity

M2


Report •

#10
February 28, 2010 at 03:59:08
That one had me wondering as well, but if it works ...

Report •

Ask Question