1.

Solve : How I can make batch file that will save list of my folders to txt file?

Answer»

How I can make BATCH file that will save list of my folders to txt file
C:\>type listDirec_astxt.bat

Code: [Select]@ echo off
cd \
dir /B /AD > direc_txt.txt
rem dir /s /B /AD > direc_txt.txt
type direc_txt.txt
Output:
C:\>listDirec_astxt.bat


app
app program
batch
bat_extra
bin
boot
cname
DECCHECK
DELL
Documents and Settings
drivers
HPDESK
jpeg
MSOCache
mydirectory
oldbat
orig
Program Files
program1
RECYCLER
TEMP
test
tmp1
tmp2
WINDOWS
.
.
.

C:\>wow, so fast!!! thanks a lot!

now I need some EXPLANATION...

it's work in root directory and how I can do same thing with "c:/windows/system" for example?Quote from: alechko on January 08, 2010, 11:59:30 AM

wow, so fast!!! thanks a lot!

now I need some explanation...

it's work in root directory and how I can do same thing with "c:/windows/system" for example?
After the /AD in the dir command, add your desired path. Bill's just goes through all the folders of the systemdrive. Quote from: alechko on January 08, 2010, 11:59:30 AM
Now I need some explanation...
It's work in root directory and how I can do same thing with "c:/windows/system" for example?

you must cd to: C:\WINDOWS\system

The following is not a batch but the information is directly from the command line


rem wc -l counts the number of directories. I use XP pro and
rem C:\WINDOWS\system has no sub directories on my machine

C:\WINDOWS\system>dir /B /AD | wc -l
0

C:\WINDOWS\system>cd ..

C:\WINDOWS>dir /B /AD | wc -l
120

C:\WINDOWS>dir /s /B /AD | wc -l
1879

C:\WINDOWS>

p.s. You may run the above without : " | wc -l"please make batch file for me, I don't understand how this work...
I need list of all folders in specific directory.
please explain how I can change directory too.

thanks!Quote from: alechko on January 11, 2010, 03:01:26 AM
please make batch file for me, I don't understand how this work...
I need list of all folders in specific directory.
please explain how I can change directory too.

thanks!
Use the code in reply #1 and read what I said in reply #3. hi, I make batch file from first reply it's work only in root, i trying to run in in other directory but not successfully...

I need batch file where I can set path to directory that I need... I dont' understand your second reply.Quote from: alechko on January 08, 2010, 07:42:44 AM
How I can make batch file that will save list of my folders to txt file
try this syntax: short and simple and i'll also add my comments for help..
DIR ; creates a list of files in a folder
c: ; identifies the files to be listed in this instance it will list all folders in your c:drive you can ammend it by drawing file as well ie. *.doc
/s ; indicates that the search should include all subdirectories
/b ; indicates the list should be bare , only including the filename and LOCATION
> ; directs the output to a file
c:\list.txt ; creates a file with this name and places the output of the dir command into it.


**this is run from the dos prompt if you go to start run and type cmd in the text box you'll get there. Type the complete syntax on one line with the directory that you are wanting to create your list from. example:
DIR c: /s /b > c:\list.txtQuote from: alechko on January 11, 2010, 04:50:39 AM
hi, I make batch file from first reply it's work only in root, i trying to run in in other directory but not successfully...

I need batch file where I can set path to directory that I need... I dont' understand your second reply.
see my post below and you can change it to any directory that you want. for example p:

C:\>type listdir.bat
Code: [Select]@ echo off
cd c:\windows\system
dir /B /AD | wc -l
echo no sub directories under "c:\windows\system"
cd c:\windows\
dir /B /AD | wc -l
dir /B /AD > direc_txt.txt
rem dir /s /B /AD > direc_txt.txt
type direc_txt.txt
Output:

C:\>listdir.bat
0
no sub directories under "c:\windows\system"
$
$NtUninstallKB960803$
.
.
.

addins
AppPatch
assembly
CAVTemp
Config
Connection Wizard
Corel
Cursors
Debug
Downloaded Installations
Downloaded Program Files
Driver Cache
ehome
Fonts
Help
HPSETUP
ie8
ie8updates
ime
inf
Installer
java
L2Schemas
Media
Microsoft.NET
msagent
msapps
msdownld.tmp
mui
Network Diagnostic
Offline Web Pages
pchealth
PeerNet
Performance
PIF
Prefetch
Provisioning
pss
Registration
repair
Resources
security
setup.pss
ShellNew
SoftwareDistribution
srchasst
Sun
system
system32
Tasks
Temp
twain_32
WBEM
Web
WinSxS

C:\WINDOWS>dir DIRECTORY_OF_FOLDER\*.* /b >list.txt


for ex

dir E:\Test\Test001\*.* /b >List.txt

Text file will b saved FRM wer batch file was ranQuote from: the_mad_joker on January 12, 2010, 08:09:54 AM

dir E:\Test\Test001\*.* /b >List.txt

Text file will be saved from where batch file was run.

"Text file will be saved from where batch file was run."

With the exception:

When there is a cd command to a new directory at the beginning of batch.


Discussion

No Comment Found