Loop through a folder and list files
Use basename
to strip the leading path off of the files:
for file in sample/*; do
echo "$(basename "$file")"
done
Though why not:
( cd sample; ls )
Assuming your shell supports it you could use parameter expansion
for path in sample/*; do
printf -- '%s\n' "${path##*/}"
done
or you could just change to that directory and do the listing there
Because *nix systems allow nearly any character to be part of a filename (including including whitespace, newlines, commas, pipe symbols, etc.), you should never parse the output of the "ls" command in a shell script. It's not reliable. See Why you shouldn't parse the output of ls.
Use "find" to create a list of files. If you are using Bash, you can insert the output of "find" into an array. Example below, with the caveat that I used a non-working "curl" command!
searchDir="sample/"
oldFiles=()
while IFS= read -r -d $'\0' foundFile; do
oldFiles+=("$foundFile")
done < <(find "$searchDir" -maxdepth 1 -type f -print0 2> /dev/null)
if [[ ${#oldFiles[@]} -ne 0 ]]; then
for file in "${oldFiles[@]}"; do
curl -F ‘data=@"$file"’ UPLOAD_ADDRESS
done
fi