-2

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

  • 2
    The fact that you state you are not a programmer does not absolve you from making any attempt whatsoever from manipulating the solutions you found. Without providing your code and an explanation of what the issue's are with it in running, your question is a direct code request and is off topic here. Please [edit your question](https://stackoverflow.com/posts/46714028/edit) including the information I have requested above. – Compo Oct 12 '17 at 16:08
  • And the sub-folders are within that main folder? – Squashman Oct 12 '17 at 16:09
  • @Squashman yes the sub-folders are within that main folder. – Hashi Mohamed Oct 12 '17 at 17:08
  • @Compo I've edited my response. Apologies, I was not aware direct code requests are not permitted. – Hashi Mohamed Oct 12 '17 at 17:11

1 Answers1

-1

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

  • 3
    Thomas, hover your cursor over the batch-file tag, and decide if this answer seems relevant! – Compo Oct 12 '17 at 16:10
  • I thought Unix shells required back ticks to assign the output of the command to a variable. – Squashman Oct 12 '17 at 16:36
  • @Thomas-The-Bombest thanks I should be able to incorporate your code to this solution [link](https://stackoverflow.com/a/26916796/8766357) and have this work. – Hashi Mohamed Oct 12 '17 at 17:13
  • 1
    @HashiMohamed, I know you never specified your Operating System or platform and that you are a beginner so I'm just letting you know that the code above is not for a standard Windows platform. – Compo Oct 12 '17 at 17:51