0

Many posts discuss how to list paths and filenames separately. However, I need them both together. Is there a way to do that?

For example:

  • Filename Filepath
  • A.xlsx /Folder/Folder/A.xlsx
  • B.xlsx /Folder/Folder/B.xlsx

Or even better if I can just output that to csv file as that is what I need in the end. One column filename. One column filepath

1 Answer 1

0

If you have in file the paths you can extract the filename on this way:

for i in `cat filename`;
do
echo `basename $i`";"$i
done

Please clarify if you have list in file. If you do not have file you can run find command to search for files in particular tree. The first line should become:

for i in `find /path -type f -name "your_wildcard_here"`;

If you do not need to filter the files you must change the first line like this:

for i in `find /path -type f`;

where /path is the starting directory you want to search

5
  • i don't. I don't have the list in file Commented Sep 30, 2016 at 8:33
  • @forgodsakehold, please check my corrected answer if this is you search for Commented Sep 30, 2016 at 8:37
  • thank you. but i'd like to print every file and folder (recursively) in a specified folder. how do modify the code? Commented Sep 30, 2016 at 8:51
  • @forgodsakehold, if you need every file check my corrected andwer Commented Sep 30, 2016 at 9:01
  • 1
    Probably best to avoid a mixed for i in $(find...) in case of oddly named files, such as those with spaces. Just use one (for i in **/*) or the other (find path -type f -printf '%f,%p\n').
    – 8bittree
    Commented Oct 13, 2016 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .