Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 2nd, 2012, 03:43 AM
stergema stergema is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 stergema User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 34 sec
Reputation Power: 0
Xlwt

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.

Reply With Quote
  #2  
Old October 3rd, 2012, 12:22 AM
stergema stergema is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 stergema User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 34 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old October 15th, 2012, 02:18 AM
davecotefilm davecotefilm is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 davecotefilm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 50 sec
Reputation Power: 0
ok

oops

Reply With Quote
  #4  
Old October 15th, 2012, 09:32 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,380 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 7 m 19 sec
Reputation Power: 383
I'm here, but lost interest as soon as I saw both an
xlwt module of which I'm unaware, and
xls which I try to avoid.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Xlwt

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap