Python Forum
How to loop in python over subdirectories and copy the output to other subdirectories
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to loop in python over subdirectories and copy the output to other subdirectories
#1
I have a Jenkinsfile with the below code in one of the stages:

sh """
    python funcs/echo/tests/test.py || true
    coverage xml funcs/echo/tests/test.py || true
"""
My folder structure is:

Output:
|-- funcs | |-- echo | | |-- app.py | | `-- tests | | `-- test.py | |-- moshe | | |-- app.py | | `-- tests | | `-- test.py | `-- sum | |-- app.py | `-- tests | `-- test.py `-- tests |-- echo | `-- tests |-- moshe | `-- tests `-- sum `-- tests
How can I loop using python3 thought the funcs folder? I tired to run the below:

my_path="funcs"
for dirs in os.walk (my_path):
    print (dirs)
but it return the below:

Output:
funcs funcs/moshe funcs/moshe/tests funcs/echo funcs/echo/tests funcs/sum funcs/sum/tests
but what I really need is to loop on those:

Output:
funcs/moshe/tests funcs/echo/tetss funcs/sum/tests
and then for each one copy the 2 output files to the target I described above
Reply


Messages In This Thread
How to loop in python over subdirectories and copy the output to other subdirectories - by arielma - Oct-22-2020, 12:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 351 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Copy documents to Teams using python SallySmith 0 2,437 Mar-23-2021, 04:27 AM
Last Post: SallySmith
  Moving Files From Subdirectories To Another Directory Harshil 5 4,120 Oct-06-2020, 10:52 AM
Last Post: ndc85430
  using 'while loop' output going into infinite loop... amitkb 2 2,037 Oct-05-2020, 09:18 PM
Last Post: micseydel
  sports Stats > table output loop problems paulfearn100 3 2,584 Jul-22-2020, 03:21 AM
Last Post: c_rutherford
  Print output in single file using pramika loop deepakkhw 1 2,140 Jul-11-2020, 11:57 AM
Last Post: j.crater
  To Copy text values to Excel using Python ksasi2k3 16 16,190 Dec-26-2019, 11:59 AM
Last Post: ashutoshdeodhar
  Output in for LOOP iterated Renym 1 1,565 Nov-17-2019, 09:15 PM
Last Post: perfringo
  Copy data from different workbooks into Master sheet with Python Fatman003 0 2,274 Aug-27-2019, 07:36 AM
Last Post: Fatman003
  How do I copy files faster with python? steckinreinhart619 7 18,667 Jul-19-2019, 11:47 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020