Page 1 of 1

File List script adding filelist

Posted: 21 Feb 2020 07:54
by sark
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

Re: File List script adding filelist

Posted: 21 Feb 2020 10:28
by Squashman
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.

Re: File List script adding filelist

Posted: 22 Feb 2020 04:28
by sark
Kicking myself for not thinking of the first option.

Thanks for that.

sark