List files with date, create directory, move to the created directory

Hi all,
i have a folder, with tons of files containing as following,
on /my/folder/jobs/
some_name_2016-01-17-22-38-58_some name_0_0.zip.done
some_name_2016-01-17-22-40-30_some name_0_0.zip.done
some_name_2016-01-17-22-48-50_some name_0_0.zip.done
and these can be lots of similar files,
some_name_2016-01-18-22-40-30_some name_0_0.zip.done
some_name_2016-01-18-22-48-50_some name_0_0.zip.done
and i have also on the same folder tons of files containing, the same name, but the date and time changes, depending on the time and date it was done,
now as it is impossible to check if a file exist on that folder,
i would like to create a script that will do the following;
list all file with a specific date
create a folder with this specific date
move all files with this date to the new created folder,
and i need to do this for every different date.

i thought some thing like this, but not working at all, it work only if i specify the date, but i dont wont to do it manually, the script must understand what to do,

so here my script;

cd /my/folder/jobs/
files="2016-01-17"
newdir="2016-01-17/"
 for i in {$files};
 do 
    
    newdir=$(echo /my/folder/jobs/$newdir)
    if ! [ -d $newdir ]; then
        echo Directory $newdir does not exist.  Creating $newdir.
        mkdir -p $newdir;
    fi
    mv "*$files*" $newdir;
done

Thanks in advance for any suggestions.

Please use code tags for data (file listing) as well!

What's the contents of $3? What's the meaning of "not working at all"?

Well, i'm away from scripts some time on,
so please modify the script as you better think and i will test it on my envirement, "not working at all" means the script as it is wright now does nothing.

BTW edited the first script,

Thank in advance.

One reason for failure might be the space in the file names which will make the for loop fail.

Ok, can you modify it or create a new one, to create a new folder for every date, and move those files to the referral folder?
Thanks.

Would this do (needs a recent shell)?

ls some* | while read FN; do DIR=${FN#*_*_}; DIR=${DIR%-*-*-*_*}; mkdir -p $DIR; mv "$FN" $DIR; done
1 Like

will test this and let you know,

!/bin/sh will do the job

thank a lot.

---------- Post updated at 02:00 PM ---------- Previous update was at 01:53 PM ----------

SOLVED