Problem using Grep for a loop

Dear All,
I have problem with generalizing my code and I can't see where the problem is.

I have a main.txt file that has all the information and then I have 4 folders (headoffice, branch, management, office) that each have a 2 of files keep.txt and throw.txt and each of them have few lines (so 4 keep and 4 throw)

I wrote a line that goes throw each line a main.txt and it creates a file with only lines that has an object name that is on the keep and not on the throw for the headoffice

grep -F -f headoffice/keep.txt main.txt | grep -v -F -f headoffice/throw | sort -u > result/headoffice-keep.txt

my problem is when I want to create a loop around it to take all the folders together as it gives me the wrong answer and I can't see why... tried millions of ways and one of them is the following

mkdir result		
FILES="folder/*/*"
for W in $FILES
do
	doc=$(basename $W) 
	mkdir result/${doc}
		grep -F -f */*/keep.txt main.txt | grep -v -F -f */*/throw.txt | sort -u > result/${doc}/${doc}-keep.txt		
done 

Can someone help me plz:confused:

I take it then that $FILES contains directories that contain a keep.txt file and a throw.txt file? If so try:

grep -Ff "$W/keep.txt" main.txt | grep -vFf "$W/throw.txt" | sort -u > "result/${doc}/${doc}-keep.txt"

For each W you certainly want to consider one keep.txt and not all */*/keep.txt ? (Dito throw.txt .)
Suggestion:

...
    doc=$(basename "$W")
    docpath=$(dirname "$W")
    mkdir result/"$doc"
    fgrep -f "$docpath"/keep.txt main.txt | fgrep -v -f "$docpath"/throw.txt | sort -u > result/"$doc/$doc"-keep.txt
...

thank you very much
I have changed few things as I wanted the results to be in a similar shaped folders (with sample folder names) e.g.

	mkdir result/${docpath}

just tested on two folders and hope it will work well when i put the rest of the files in