Fedora Linux Support Community & Resources Center
  #1  
Old 8th October 2009, 10:29 PM
Deonis Offline
Registered User
 
Join Date: May 2008
Location: Montreal
Posts: 198
linuxfedorafirefox
How to make a list of txt ogg or other files?

Hello
Do somebody know how to make a list of all mp3 ogg or any other files in linux and save it as csv. Or, do somebody know a program or python script which allow you to do that by just pointing at the location with this files??

Any help?
Reply With Quote
  #2  
Old 8th October 2009, 10:42 PM
William Haller Online
Registered User
 
Join Date: Jul 2005
Age: 53
Posts: 1,079
linuxfedorakonqueror
find / -name '*.ogg' -type f >mylist.csv

comes to mind...
Reply With Quote
  #3  
Old 9th October 2009, 02:49 AM
Deonis Offline
Registered User
 
Join Date: May 2008
Location: Montreal
Posts: 198
linuxfedorafirefox
Thanks for reply !!!
It's look like a very handy method ! Is there a way to put file size and name of the file separately ??? Or I want too much!?

Last edited by Deonis; 9th October 2009 at 02:54 AM.
Reply With Quote
  #4  
Old 9th October 2009, 03:30 AM
William Haller Online
Registered User
 
Join Date: Jul 2005
Age: 53
Posts: 1,079
linuxfedorakonqueror
You can always get more creative with the find command

Add a --exec ls -la {} \;

to get the file information, followed by a cut command based on columns to isolate the file size and name.

Do a man find and man cut for more information.
Reply With Quote
  #5  
Old 9th October 2009, 03:40 AM
jpollard Online
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,771
linuxfedorafirefox
I would suggest using perl... but for a special reason.

Just because a file has a given extension doesn't mean the file really is that type. I would tend to
use the perl find module to list all files, and then verify the file type with the "file" utility.

This also allows you to get the directory entry via stat.

The file module includes a file type function (using magic numbers to identify file types).

The major advantage of using perl is that only one process is needed for the entire thing.
You also have a possibility to to this in a multi-threaded manner - where speed is necessary -
I've been able to scan a filesystem with over 40 million files in about 45 minutes that way.
Reply With Quote
  #6  
Old 18th October 2009, 07:16 PM
Deonis Offline
Registered User
 
Join Date: May 2008
Location: Montreal
Posts: 198
linuxfedorafirefox
finally this work just as I expected:
sudo find /media/ -name '*.ogg' -type f -ls >mylist.csv
Thanks to everybody who were trying to help !!!
Reply With Quote
  #7  
Old 18th October 2009, 07:50 PM
Deonis Offline
Registered User
 
Join Date: May 2008
Location: Montreal
Posts: 198
linuxfedorafirefox
# this is the python script which is doing about a same thing except no formatting. And
# unfortunately I am not that good at python so I can not really figure out how
# to make similar output of "find" command. if somebody will figure out please
# post here
Code:
import os, time
ff = raw_input("type a name of the folder to scan:  ")
# ff = '/user/folder/'
allfiles = []
subfiles = []

for root, dirs, files in os.walk(ff):
     for f in files:
         if f.endswith('.mp3') or f.endswith('.ogg'):
             allfiles.append(os.path.join(root, f))
             if root != ff: 
                  subfiles.append(os.path.join(root, f))   
#stats = os.stat(root)
#lastmod_date = time.localtime(stats[8])
#date_file_tuple = lastmod_date, files
#files.append(date_file_tuple)
#files.sort()
#files.reverse() 
#print "%-60s %s" % ("filename:", "last modified:")
#for file in files:
                   #  folder, file_name = os.path.split(file[1])
                    # file_date = time.strftime("%m/%d/%y %H:%M:%S", file[0])
                    # print "%-60s %s" % (file_name, file_date)   
print "*"*80          
print "allfiles=", allfiles
print "-"*112

Last edited by Deonis; 18th October 2009 at 07:54 PM.
Reply With Quote
  #8  
Old 19th October 2009, 12:35 PM
jpollard Online
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,771
linuxfedorafirefox
The only difference I see is that find prints the filename as discovered instead of putting it in an array. Or
forks/execs a process to do something with it - such as "ls" -- find . -depth -name "..." -o -name "..." -exec ls -l '{}' ';'

The main disadvantage of that is that a new process is created for each file (lots of fork/exec). What I was suggesting
was to use the language capabilities to do a file content check the way the "file" utility does. It reads the first 16 bytes
(or so) to check against the "magic" (man magic) list to determine content. Takes longer than an extension list,
but if files are not always ending in the default extension, it works quite well.
Reply With Quote
Reply

Tags
files, list, make, ogg, txt

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make hidden files? Ecstasy Using Fedora 2 26th February 2009 01:56 PM
How to rename a list of files jimqi Using Fedora 6 2nd July 2008 01:32 AM
using yum with a list of rpm files yiown Installation, Upgrades and Live Media 25 21st April 2008 05:22 PM


Current GMT-time: 15:45 (Wednesday, 23-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat