#!/usr/bin/perl -w #) { chomp; next unless length; next if $_ eq '.'; # Do we have something like a file-count and tab # before the filename? $pre = ''; if (/\t/) { ($pre, $rest) = split(/\t/); $_ = $rest; } # Filetype? $ft = -d $_ ? '"Folder"' : '"-"'; # Handle the directory part of the filename. $orig = $_; if (m![^/]*/([^/]*)$!) { $base = $1; s![^/]*/([^/]*)$!,[#FILE#]!s; } # Escape any double-quotes in the filename. $base =~ s/"/""/g; # Handle the base part of the filename. # After this, $_ holds the indentation plus basename # and $orig holds the complete path. s![^/]*/!,!sg; s!\[#FILE#\]!"$base"!; # Generate and print the final CSV record. $out = length($pre) ? $pre : ''; $out .= "$ft,$_,"; print "$out"; } exit(0);