convert all txt files delimiter '|' from dir path and convert to csv and save in a location using python?

i have tried this code which is hardcoded.

```
import csv

txt_file = r"SentiWS_v1.8c_Positive.txt"
csv_file = r"NewProcessedDoc.csv"

with open(txt_file, "r") as in_text:
    in_reader = csv.reader(in_text, delimiter = '|')
    with open(csv_file, "w") as out_csv:
        out_writer = csv.writer(out_csv, newline='')
        for row in in_reader:
            out_writer.writerow(row)

```

Expecting csv files with same file names in dir path for all txt files in path location