-1

I have the following code:

for %%F in ("C:\test\*.csv") do 
(
    echo TEST1                                                 >test.txt
    echo TEST2                                                  >>test.txt

)
pause

For each csv-file it should create/overwrite a file and append some content to it. However it doesn't work, the file won't be created. When I do it without a loop it works:

   echo TEST1                                                 >test.txt
   echo TEST2                                                  >>test.txt

I am not very familiar which cmd commands, but what is here the problem. I need the %%F (filename of the csv) because I use it later in the for-loop

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
NoName123
  • 137
  • 5
  • 20
  • please, post your actual code (at least the relevant part), so we don't need to guess what you're really trying to do. – elzooilogico Jul 12 '17 at 08:59
  • A tip about file redirection, read the last two paragraphs of [this post](https://stackoverflow.com/questions/44455729/correct-syntax-for-nested-for-loops-in-batch-file/44455914#44455914) – elzooilogico Jul 12 '17 at 09:03

1 Answers1

1

What do you mean by "work?"

The opening parenthesis must be on the same line as the do

for %%F in ("C:\test\*.csv") do (

Since you are using > in the first echo, for each filename the file will be created anew.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • thx, but now i get another problem. I get the message: "The process cannot access the file because it is being used by another process". Do you know how to solve this issue? it appears that my own script is locking the file – NoName123 Jul 12 '17 at 08:54