Batch script to move files to folders based on part of file name

1.3k views Asked by At

I have a relatively simple but time consuming task of moving certain files to designated folders.

Example File names:

01234567.Description.Date.FileExtension
89ABCDEF.Description.Date.FileExtension

Example Folders:

01234567
89ABCDEF

All are within a folder, I just want a script that reads the first portion of the name of the file up to the period . and move that file to the matching folder.

I have tried the following solution link but I think @Thomas-The-Bombest answer below should be enough to manipulate it to do what I'm trying to achieve. Thank you

1

There are 1 answers

4
Thomas-The-Bombest On

You can use cut -d. -f1 to grab the whatever is before the first .

Simply store this in a variable and use it to name a folder with the mkdir command

i.e.

$folderName = echo 01234567.Description.Date.FileExtension | cut -d. -f1

mkdir /path/to/wherever/$folderName