List files and add ;

List files and add ;

am 02.10.2007 13:58:51 von mosfet

Hi,

I would like to create a csv file with the content of one of my directory.

home/foo:
toto.txt;
titi.txt;
....

Re: List files and add ;

am 02.10.2007 14:04:50 von mosfet

mosfet a écrit :
> Hi,
>
> I would like to create a csv file with the content of one of my directory.
>
> home/foo:
> toto.txt;
> titi.txt;
> ...
>
>
Actually I want more :

I want the files displayed like this:


#FilePath;FileExt;FileSize(bytes)
/home/vince/toto.txt;.txt;108
/home/vince/titi.txt;.txt;1425
....

Re: List files and add ;

am 02.10.2007 14:31:44 von Janis Papanagnou

On 2 Okt., 14:04, mosfet wrote:
> mosfet a =E9crit :> Hi,
>
> > I would like to create a csv file with the content of one of my directo=
ry.
>
> > home/foo:
> > toto.txt;
> > titi.txt;
> > ...
>
> Actually I want more :
>
> I want the files displayed like this:
>
> #FilePath;FileExt;FileSize(bytes)
> /home/vince/toto.txt;.txt;108
> /home/vince/titi.txt;.txt;1425
> ...

Depending on what you consider an extension in case of files named,
eg., arch.tar.gz the following will create a list if the filenames
contain no spaces (or other special/control characters)...

ls -l /home/vince/* |
awk -v OFS=3D\; '{print $NF,substr($NF,index($NF,".")),$5}'

What about subdirectories?

Janis

Re: List files and add ;

am 02.10.2007 14:42:22 von cichomitiko

mosfet wrote:
> mosfet a écrit :
>> Hi,
>>
>> I would like to create a csv file with the content of one of my
>> directory.
>>
>> home/foo:
>> toto.txt;
>> titi.txt;
>> ...
>>
>>
> Actually I want more :
>
> I want the files displayed like this:
>
>
> #FilePath;FileExt;FileSize(bytes)
> /home/vince/toto.txt;.txt;108
> /home/vince/titi.txt;.txt;1425
> ...

With zsh (assuming path different than "/"):

zsh 4.3.4% ls -l
total 8
-rw-r--r-- 1 radoulov radoulov 3 2007-10-02 14:35 1.txt
-rw-r--r-- 1 radoulov radoulov 10 2007-10-02 14:36 2.txt
zsh 4.3.4% zmodload zsh/stat
zsh 4.3.4% for f (*) print -r "$PWD/$f;.$f:e;$(stat +size -N "$f")"
/home/radoulov/test/1.txt;.txt;3
/home/radoulov/test/2.txt;.txt;10


Dimitre

Re: List files and add ;

am 02.10.2007 14:59:54 von Icarus Sparry

On Tue, 02 Oct 2007 14:04:50 +0200, mosfet wrote:

> mosfet a écrit :
>> Hi,
>>
>> I would like to create a csv file with the content of one of my
>> directory.
>>
>> home/foo:
>> toto.txt;
>> titi.txt;
>> ...
>>
>>
> Actually I want more :
>
> I want the files displayed like this:
>
>
> #FilePath;FileExt;FileSize(bytes)
> /home/vince/toto.txt;.txt;108
> /home/vince/titi.txt;.txt;1425
> ...

Do all your files have extensions?
You seem to want a "semicolon seperated file", rather than a comma
seperated one, do any of your filenames or paths contain a semicolon?
Do any of your filenames contain any special characters, in particular
newlines, spaces, tabs?
Does your csv format have any kind of quoting? If so, how does it work?
How do you represent a quote character in the file?
Do you have any subdirectories in this directory? If so do you want the
contents of these subdirectoies added to the csv file or not?

The approach I would use would be to use either "perl", or "find | sed",
but we need a better specication of the problem.

Do you have GNU find?


find . -type f -printf "%p;%f;%s\n" |
sed -e 's/;.*\./;./' -e 's/;[^.]*;/;;/'