简体   繁体   中英

How to extract the filename and path from sub directories and need to write the output into a csv file using unix shell script

I need to extract the filenames as well as path in a csv file from different subdirectories in a parent directory using unix shell script .

Requirement : I have different subfolders in a parent. Every subfolder ha one image file. Now , I need to list the filename and path of that file , And need to write the filenames and path into a csv file for all the sub directories.

Please help me out.

-Sudhir.

If I understand correct, you want write filename and path to csv file.

#!/bin/bash

echo "Dir, Name" > "csvfile.csv"

files=$(find /YOURPATH -type f)

for f in $files
do

dir=$(dirname $f)
name=$(basename $f)
echo "$dir, $name" >> "csvfile.csv"

done

Find all files in /YOURPATH , write path and filename to csvfile.csv .

Or If you want to find just image file and if you know type, you can use like this:

find /YOURPATH -type f -name *.jpg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM