Python Forum
Append root directory folder and subdirectory to filename
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Append root directory folder and subdirectory to filename
#5
(Aug-04-2020, 10:00 PM)bowlofred Wrote: By doing path.split(dirpath)[-1], you're asking for "the last component of the path", which is a str.

If you just remove the bracket, you're asking for all components, which will be a collection (a tuple in this case). You need it to be a string, probably with underscores between them, so you want (another) join. Something like:

"_".join(path.split(dirpath))

I apologize for all these questions, but where do I add that additional join?
Reply


Messages In This Thread
RE: Append root directory folder and subdirectory to filename - by glittergirl - Aug-05-2020, 04:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 667 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  delete all files and subdirectory from a main folder mg24 7 1,733 Oct-28-2022, 07:55 AM
Last Post: ibreeden
  Append files and add column with last part of each filename NiKirk 0 2,682 Feb-04-2022, 07:35 AM
Last Post: NiKirk
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,637 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,550 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  How to skip a folder directory in a loop mfkzolo 2 12,813 Nov-18-2020, 07:56 AM
Last Post: mfkzolo
  Python Cut/Copy paste file from folder to another folder rdDrp 4 5,218 Aug-19-2020, 12:40 PM
Last Post: rdDrp
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 2,666 Apr-22-2020, 01:01 PM
Last Post: deanhystad
  How to change directory to any folder where python is not installed ? firashelou 4 2,705 Apr-03-2020, 02:43 PM
Last Post: firashelou
  Python 2.7 Import error. Directory and filename conflict petcoo00 2 2,451 Feb-02-2020, 08:46 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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