Hi,

Im trying to make a batch script which can go through a directory and pick all the .txt files and copy the name in a file. Ive been able to make a script which can do this in a particular folder but if there is a folder in the folder it doesnt check in that, this is what I have so far,

@echo off

rem get files into text file
 
set PD=%CD%
set WW=%1
set WD=%WW%

CD %WD%
dir /b | gawk "{print $1}" | grep \.c | sed "s/\.txt//g" > %PWD%\testing2.txt

I was thinking of using recursion to to go deeper into the folders but im not sure how to identify a folder, If I can I can use it as a kind of a stop case.

Thanks,
Rahul

use dir /b /s

/s Displays files in specified directory and all subdirectories.

Thanks, that solves my immeadiate problem. Im using gawk to get the last column data from the file.
My file looks like this,

C:\Documents and Settings\name\test\byebye.c
C:\Documents and Settings\name\test\hello.c
C:\Documents and Settings\name\test\hey.h
C:\Documents and Settings\name\test\New Folder
C:\Documents and Settings\name\test\New Folder (2)
C:\Documents and Settings\name\test\New Folder\tesdfsftsdfds.c

using the command,

gawk "{print $NF|"

the data is split into,


Settings\name\test\byebye.c
Settings\name\test\hello.c
Settings\name\test\hey.h
Settings\name\test\New Folder
Settings\name\test\New Folder (2)
Folder\tesdfsftsdfds

What I need is to get the last file name, is it possible to get these by using gawk again or is there a way to space the data after a \, that way i can use gawk better?

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.