Note that there are some explanatory texts on larger screens.

plurals
  1. POPython usage of os.renames
    primarykey
    data
    text
    <p>I am trying to rename files using python but I cannot figure exactly where is the error, perhaps I am too tired as trying to do this for over 30 hours non-stopping.</p> <p>The actual problem is quite visible when you look at the <strong>desired output</strong> and in the <strong><em>actual</em></strong> one.</p> <pre><code>#!/usr/bin/env python import sys import os import glob if __name__ == '__main__': input_file=sys.argv[1] File= open(input_file) while True: line=File.readline() words = line.split() if not ("call" or "song") in words: break folder_dest= words[0] +" "+ words[1] subfolder=words[3] filename=words[4].replace(".wav","") folder_now=words[7].replace(".wav","") os.chdir(folder_now) i=1 for files in glob.glob("*.wav"): os.renames(files,"../"+folder_dest+"/"+subfolder+"/"+filename+"-"+'{:03}'.format(i)+".wav") i+=1 os.chdir("..") </code></pre> <p><strong>More explanation:</strong></p> <p>I have this input file</p> <pre><code>Aegolius harrisii song 10009.wav Aegolius harrisii song 21.wav Aegolius harrisii song 483_Aegolius%20harrisii_F27_Itatira_28_IV_2004_Weber%20Girao.wav Aegolius harrisii song 22.wav Gnorimopsar chopi song 1000517.wav Gnorimopsar chopi song 825.wav Myiobius barbatus call Myiobius.sulphureipygius9402-1.wav Myiobius barbatus call 1146.wav Myiobius barbatus song 1001.wav Myiobius barbatus song 1147.wav Muscipipra vetula call 1000682.wav Muscipipra vetula call 1122.wav </code></pre> <p>This is the current folder structure:</p> <pre><code>1 ├── parte_1.wav └── parte_2.wav 2 ├── parte_1.wav ├── parte_2.wav ├── parte_3.wav ├── parte_4.wav ├── parte_5.wav └── parte_6.wav </code></pre> <p>...</p> <p>Here is the output as now:</p> <pre><code>Aegolius harrisii/ ├── 100015.wav │   ├── Aegolius-001.wav │   └── Aegolius-002.wav └── AEGOLI~1.wav ├── Aegolius-001.wav ├── Aegolius-002.wav ├── Aegolius-003.wav ├── Aegolius-004.wav ├── Aegolius-005.wav └── Aegolius-006.wav </code></pre> <p>desired output</p> <pre><code>Aegolius harrisii/ ├── call │   ├── 100015-001.wav │   └── 100015-002.wav └── song ├── AEGOLI~1-001.wav ├── AEGOLI~1-002.wav ├── AEGOLI~1-003.wav ├── AEGOLI~1-004.wav ├── AEGOLI~1-005.wav └── AEGOLI~1-006.wav </code></pre> <p>The question is: what I'am doing wrong in os.renames?</p> <p>Thank you, for reading/answering this!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload