3 Replies - 1232 Views - Last Post: 02 October 2012 - 10:15 PM Rate Topic: -----

#1 stergema  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-March 08

xlwt

Posted 02 October 2012 - 02:47 AM

Hello everyone!
I have a piece of code witch takes a list of subfolders(C:/desktop/movie/1/filmenamelalal,2/filmenametralala,3,4,5,6,7,8,9 and so on) and creates a list of xls files(C:/desktop/text/1.xls, 2.xls, 3xls, and so on).
In that files (xls) i want to write the names of the files from that subfolder in each row for xnumber of files in the subfolder:
xls:row0filmenamelalal
xls:row0filmenametralala
and so on...
The code that i have so far is:
import os
import xlwt 
import os.path

#link = raw_input("Linkul: ")



for dirname, dirnames, filenames in os.walk(r"C:/Users/s/Desktop/filme/"):
for subdirname in dirnames:
foldere_filme = os.path.join(dirname, subdirname)
numarul_folderelor = foldere_filme.replace("C:/Users/s/Desktop/filme/", "")
print numarul_folderelor
for filenames in os.listdir(foldere_filme):
numele_pt_text = filenames.replace(".avi", "")
print numele_pt_text
wbk = xlwt.Workbook()
sheet = wbk.add_sheet('sheet 1', cell_overwrite_ok=True)
sheet.write(0,0,numele_pt_text)
sheet.write(1,0,numele_pt_text)
sheet.write(2,0,numele_pt_text)
sheet.write(3,0,numele_pt_text)
wbk.save("C:/Users/s/Desktop/text/"+numarul_folderelor+".xls")

It prints ok, but when it saves it saves into the xls it saves only the last name of the file from the subfolder.
Thank you in advanced.

Is This A Good Question/Topic? 0
  • +

Replies To: xlwt

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,612
  • Joined: 23-August 08

Re: xlwt

Posted 02 October 2012 - 03:39 AM

Where's your indentation? It's a little hard to find problems in Python code without the correct any indentation.
Was This Post Helpful? 0
  • +
  • -

#3 stergema  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-March 08

Re: xlwt

Posted 02 October 2012 - 04:07 AM

View PostJackOfAllTrades, on 02 October 2012 - 03:39 AM, said:

Where's your indentation? It's a little hard to find problems in Python code without the correct any indentation.

:D
import os
import xlwt
from xlwt import *
import os.path

#link = raw_input("Linkul: ")



for dirname, dirnames, filenames in os.walk(r"C:/Users/s/Desktop/filme/"):
    for subdirname in dirnames:
        foldere_filme = os.path.join(dirname, subdirname)
        numarul_folderelor = foldere_filme.replace("C:/Users/s/Desktop/filme/", "")
        wbk = xlwt.Workbook()
        sheet = wbk.add_sheet('sheet 1', cell_overwrite_ok=True)
        print numarul_folderelor #1,2,3,4,5...
        for filenames in os.listdir(foldere_filme):
            numele_pt_text = filenames.replace(".avi", "")
            print numele_pt_text
            for i in range(15):
                sheet.write(i,0,numele_pt_text)
            wbk.save("C:/Users/s/Desktop/text/"+numarul_folderelor+".xls")



Was This Post Helpful? 0
  • +
  • -

#4 stergema  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-March 08

Re: xlwt

Posted 02 October 2012 - 10:15 PM

No one? Here's a simpler aproach:
import os
import xlwt
import os.path
from win32com.client import Dispatch
#link = raw_input("Linkul: ")
for dirname, dirnames, filenames in os.walk(r"C:/Users/s/Desktop/filme/"):
    for subdirname in dirnames:
        foldere_filme = os.path.join(dirname, subdirname)
        numarul_folderelor = foldere_filme.replace("C:/Users/s/Desktop/filme/", "")
        print numarul_folderelor #1,2,3,4,5...
        for filenames in os.listdir(foldere_filme):
            numele_pt_text = filenames.replace(".avi", "")
            print numele_pt_text
            root_text = "C:/Users/s/Desktop/text/"+numarul_folderelor+".txt"
            fisier_text = open(""+root_text+"", "w")
            fisier_text.writelines(
                           "Full Movie: \n\n\nwatch "
                           +numele_pt_text+" online free, watch "
                           +numele_pt_text+" online")
            fisier_text.close()

It only saves in the text files: root_text = "C:/Users/s/Desktop/text/"+numarul_folderelor+".txt" the last filename from the list in within the subfolders, i want to save all of them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1