Python Forum
Moving files to Folders - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Moving files to Folders (/thread-32620.html)

Pages: 1 2


Moving files to Folders - giddyhead - Feb-22-2021

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)



RE: Moving files to Folders - Larz60+ - Feb-22-2021

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



RE: Moving files to Folders - giddyhead - Feb-22-2021

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?


RE: Moving files to Folders - giddyhead - Feb-22-2021

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


RE: Moving files to Folders - giddyhead - Feb-23-2021

(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.


RE: Moving files to Folders - deanhystad - Feb-23-2021

What does .find() return?


RE: Moving files to Folders - Larz60+ - Feb-23-2021

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


RE: Moving files to Folders - giddyhead - Feb-23-2021

(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.


RE: Moving files to Folders - giddyhead - Feb-23-2021

(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.


RE: Moving files to Folders - Larz60+ - Feb-23-2021

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