Python Forum
n00b help with referencing files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
n00b help with referencing files
#7
I don't think you need os.walk(), since you're not recursing into those directories (it would work, it's just more complicated than you need).  glob.glob() could do this just fine.

import glob, pathlib

destination = "/this/other/different/path/to/{0}/filetomodify"

for ref in glob.glob("/this/path/to/*/refFile"):
   path = pathlib.Path(ref)
   folder = path.parent.name
   with open(ref) as refFile:
       with open(destination.format(folder), "w") as file_to_modify:
           for line in refFile:
               # line formatting here
               print(line, file=file_to_modify)
Reply


Messages In This Thread
n00b help with referencing files - by theturd - Jul-11-2017, 03:58 PM
RE: n00b help with referencing files - by DeaD_EyE - Jul-11-2017, 05:14 PM
RE: n00b help with referencing files - by theturd - Jul-19-2017, 02:16 PM
RE: n00b help with referencing files - by nilamo - Jul-19-2017, 03:19 PM
RE: n00b help with referencing files - by theturd - Jul-19-2017, 03:54 PM
RE: n00b help with referencing files - by nilamo - Jul-19-2017, 04:09 PM
RE: n00b help with referencing files - by theturd - Jul-21-2017, 03:17 PM
RE: n00b help with referencing files - by nilamo - Jul-21-2017, 04:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  name 'lblstatus' is not defined when referencing a label KatManDEW 4 1,747 Apr-21-2022, 12:33 PM
Last Post: KatManDEW
  Dictionary Referencing nickdavis2017 1 1,697 Nov-20-2021, 06:24 PM
Last Post: deanhystad
  Referencing string names in df to outside variables illmattic 1 1,465 Nov-16-2021, 12:47 PM
Last Post: jefsummers
  Referencing a fixed cell Mark17 2 2,198 Dec-17-2020, 07:14 PM
Last Post: Mark17
Sad need help in referencing a list n00bdev 2 1,953 Nov-01-2020, 12:06 PM
Last Post: buran
  Issue referencing new instance from other class nanok66 3 2,379 Jul-31-2020, 02:07 AM
Last Post: nanok66
  referencing another method in a class Skaperen 6 2,865 Jul-02-2020, 04:30 AM
Last Post: Skaperen
  Theory behind referencing a dictionary rather than copying it to a list sShadowSerpent 2 2,213 Mar-24-2020, 07:18 PM
Last Post: sShadowSerpent
  n00b question millpond 6 3,600 Jul-13-2019, 06:41 AM
Last Post: Gribouillis
  "not defined" error in function referencing a class Exsul 2 3,807 Mar-27-2019, 11:59 PM
Last Post: Exsul

Forum Jump:

User Panel Messages

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