Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving files to Folders
#1
Hello everyone, I am trying move files based upon a the names in the spreadsheet. The files in the folder also has the same name. What I want to do is to move the files to specific folders for example:

Column N1:Filename, N2:Outro.mp3, N3:Intro.mp3, N4:piano.mp3, etc
The folder where the Files are have the same names: Outro.mp3, N3:Intro.mp3, N4:piano.mp3, etc


In Column A in the same spreadsheet they are two albums Instrumental and Vocals.

Lastly in the root folders of Instrumental and Vocals are folders of combined values of 3 columns for example 1 - HGH - Tonic(Script), 2 - LOW - Legat(Pause), etc. How can the code below be modified to search for the songs in the folder as well as the excel document and separate them by albums and into the subfolders 1 - HGH - Tonic(Script), 2 - LOW - Legat(Pause) which are also folders from combined values in the same spreadsheet? Thanks


for root, dirs, files, in os.walk('C:\\Users\\mrdrj\\Desktop\\NASB - Copy\\'): # Location of Songs
        for name in files: # List of Songs in Folder
            for songnmz in sngnms: #List of Corrected Songs in Excel
                if name.find(songnmz) and albmz == 'NTt':
                    print(name)
Reply
#2
Please show:
  1. A sample spreadsheet, just one row
  2. Source folder file name (that match spreadsheet sample)
  3. Corrected file folder filename (that match spreadsheet sample)
  4. new file name for above
Reply
#3
I have tried to drag and drop the spreadsheet with only the first row and with the file names however it keeps asking to download. Is there another way I can add it to the forum?
Reply
#4
Update: The following is the link Excel Document to the excel document. On the 2nd Tab it has the root folder and the subfolders as well. Thanks
Reply
#5
(Feb-22-2021, 04:45 AM)giddyhead Wrote: Update: The following is the link Excel Document to the excel document. On the 2nd Tab it has the root folder and the subfolders as well. Thanks

Quote:Update statement: I am have the following for loops and what I am attempting to accomplish is to compare the files in the folder with the files names in the excel document and to see if they are one of two albums(OT or NT). If they are for example OT they will be moved to the OT subdirector ->Subfolders:->1 - GEN - Genesis, 2 - EXO - Exodus, etc and the same if NT ->Subfolders:->1 - MAT - Matthew, 2 - MRK - Mark, etc

for root, dirs, files, in os.walk('C:\\Users\\mrdrj\\Desktop\\Stephen Johnston\\NASB - Copy\\'): # Location of Songs
    for name in files: # List of Songs in Folder
        for songnmz in sngnms: #List of Corrected Songs in Excel
            for albmz in albm:
                if name.find(songnmz):# and songnmz albmz == 'Nasb Audio Bible Old Testament':
                    if songnmz == name and albmz == 'Nasb Audio Bible Old Testament':
                        print('name', name)
                    #os.shutil
                else:
                    print('Not Old Testament')
                    #os.shutil
When I run the above code I the Not Old Testament is what comes comes up. How can this code be fixed? Thanks.
Reply
#6
What does .find() return?
Reply
#7
Quote:Is there another way I can add it to the forum?
If you click on New reply, at the bottom of the page you will see New Attachment.
click on browse, find the file and then open.
Next click Add attachment, then insert into post
Reply
#8
(Feb-23-2021, 02:09 AM)deanhystad Wrote: What does .find() return?

When I use print('List of Names', name) under the name.find(songnmz) it produces multiple instances of the same files for example, file 1(several times) then goes to next file 2(several times), etc.
Reply
#9
(Feb-23-2021, 03:47 AM)Larz60+ Wrote:
Quote:Is there another way I can add it to the forum?
If you click on New reply, at the bottom of the page you will see New Attachment.
click on browse, find the file and then open.
Next click Add attachment, then insert into post

Thanks for the information. When I click on New reply it resets to the quick reply option.
Reply
#10
you should be able to attach after 5 posts see rules here: https://python-forum.io/misc.php?action=help&hid=31
perhaps you are not scrolling down far enough on the New Reply page (attach is at bottom).
Works for me, but my account is different. Please try again
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using zipfile module - finding folders not files darter1010 2 393 Apr-06-2024, 07:22 AM
Last Post: Pedroski55
  Create new folders and copy files cocobolli 3 1,608 Mar-22-2023, 10:23 AM
Last Post: Gribouillis
  Copy only hidden files and folders with rsync Cannondale 2 1,092 Mar-04-2023, 02:48 PM
Last Post: Cannondale
  Moving specific files then unzipping/decompressing christophereccles 2 2,423 Apr-24-2021, 04:25 AM
Last Post: ndc85430
  code to read files in folders and transfer the file name, type, date created to excel Divya577 0 1,917 Dec-06-2020, 04:14 PM
Last Post: Divya577
  Moving Files From Subdirectories To Another Directory Harshil 5 4,120 Oct-06-2020, 10:52 AM
Last Post: ndc85430
  Calling Variables from Other Files in Different Folders illmattic 14 5,772 Aug-01-2020, 07:02 PM
Last Post: deanhystad
  sub-folders in folders from text line jenost 1 1,620 Mar-31-2020, 07:16 AM
Last Post: ndc85430
  Moving Files Evil_Patrick 4 2,626 Oct-02-2019, 02:56 AM
Last Post: Evil_Patrick
  Accessing files in various directories and folders ccuny 2 2,234 May-08-2019, 12:11 PM
Last Post: ccuny

Forum Jump:

User Panel Messages

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