If all you want is to get the file's name and use it to get the right target directory, you can do:
#!/bin/bash
for i in /home/userA/folder/*.txt
do
## Get the file name
str1="${i##*/}"
## Get the target directory
dir="/home/userA/folder2/${str1%.txt}/"
done
This is using the shell's native string manipulation features. ${var##pattern} removes the longest match of pattern from the start of $var and ${var%pattern} removes the shortest match of pattern from the end of $var. So, ${i##*/} removes everything until the last / (the path) from the file name and ${i%.txt} removes the string .txt from the end of it.