# Create output files from an input file that has the same name as it for all file in a directory

**URL:** <https://forum.anaconda.com/t/create-output-files-from-an-input-file-that-has-the-same-name-as-it-for-all-file-in-a-directory/45574>\
**Category:** Data Science, ML & AI\
**Created:** [November 11, 2022, 2:13pm UTC](https://forum.anaconda.com/t/create-output-files-from-an-input-file-that-has-the-same-name-as-it-for-all-file-in-a-directory/45574 "2022-11-11T14:13:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattirai](https://avatars.discourse-cdn.com/v4/letter/m/c2df01/32.png) [@mattirai](https://forum.anaconda.com/u/mattirai)\
**Post date:** [November 11, 2022, 2:13pm UTC](https://forum.anaconda.com/t/create-output-files-from-an-input-file-that-has-the-same-name-as-it-for-all-file-in-a-directory/45574/1 "2022-11-11T14:13:12Z")

</div>

Good morning.  
I would need a script that reads information in one file and reports it in an order I indicated in another text file.  
With simple input/output statements I managed to do it but the problem is that I need this to be done for all the files in the directory and that each output produced has the same name as the file from which it comes.  
Could someone help me?  
I am new to Python but I have to learn quickly for my master’s thesis work.

---

<div class="post-metadata">

**Author:** ![sweller](https://avatars.discourse-cdn.com/v4/letter/s/c2df01/32.png) [@sweller](https://forum.anaconda.com/u/sweller)\
**Post date:** [November 17, 2022, 4:44pm UTC](https://forum.anaconda.com/t/create-output-files-from-an-input-file-that-has-the-same-name-as-it-for-all-file-in-a-directory/45574/2 "2022-11-17T16:44:46Z")

</div>

Welcome to the Anaconda Community!

One thing you could do is use the os.listdir() command to get a list of files and names in a directory, then perhaps use a ‘for-range()’ statement to loop over the filenames.

Here is a reference that should help:

> **[Python | os.listdir() method - GeeksforGeeks](https://www.geeksforgeeks.org/python-os-listdir-method/)**
>
> A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

Let me know how the project goes!
