Reputation: 199
I'm making a shell script that I need to make a loop. I have a directory called Files. Inside Files there are two folders. Each holding 500 files (folder1 and folder2). I need to get the filenames from both folder1 and folder2 because I need to concatenate the filename in folder1 with folder2. It needs to do this for every single file in there. So 250,000 times.
Anyone know how I would write that loop so that I can get all the names from both directories and loop correctly?
Upvotes: 1
Views: 145
Reputation: 8588
Assuming you're in bash, then something like this
cd Files
for f1 in folder1/*
do
for f2 in folder2/*
do
concat_name="${f1#*/}-${f2#*/}"
done
done
Upvotes: 1
Reputation: 618
something like this should do, assuming that the two subdirectories are called dir1
and dir2
, this example only echoes
the names naturally..
#!/bin/bash
for d1 in `ls Files/dir1`;
do
for d2 in `ls Files/dir2`;
do
echo ${d1}_${d2}
done
done
Upvotes: 0