File List script adding filelist

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sark
Posts: 7
Joined: 21 Feb 2020 07:37

File List script adding filelist

#1 Post by sark » 21 Feb 2020 07:54

Hi all.

I'm new to scripting and have been trying to solve much of what I want to achieve via the web.
Mostly this is successful, but sometimes it's difficult to know what to type in the search.
I have one such issue here, I'm hoping can be solved.

Code: Select all

(for %i in (*.txt) do @echo file '%i') > fileList.txt
The above creates a .txt list of specific files in a folder. It works just fine, but when the files being
searched for are .txt files it adds the newly created filelist.txt name to the list of files.
It's generally on the end, so is easily removed, but there may be times when this is part of
a more detailed script and it could become an issue.

I'm trying to learn, so would appreciate how to resolve this, or where to find information to figure this out.

Many thanks

sark

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: File List script adding filelist

#2 Post by Squashman » 21 Feb 2020 10:28

You got several options but will require more code.

1) Write the output file to a temp folder and then move it back to the folder you want.
2) Write the output file to a temp file name and then rename it back to the file you want.
3) Capture the output of the DIR command piped to the FIND command with a FOR /F so that it excludes the Output File.

I think the first two would be the easiest to implement.

sark
Posts: 7
Joined: 21 Feb 2020 07:37

Re: File List script adding filelist

#3 Post by sark » 22 Feb 2020 04:28

Kicking myself for not thinking of the first option.

Thanks for that.

sark

Post Reply