Creating folders by file names

1

I'm trying to find a way to create a folder for every file in a directory. I then want to copy each file into its created folder. These files are currently hosted on AWS (S3).

So for example if I have three files, a.jpg, b.jpg and c.jpg. I want to create three folders, a, b and c. And then copy a.jpg into a folder, b.jpg into b folder and c.jpg into c folder. I have lots of files so doing it manually doesn't seem like a good option.

Does anyone have any idea if this is possible?

BobDoleForPresident

Posted 2019-09-06T15:53:24.877

Reputation: 111

What purpose would he have for so doing? – DrMoishe Pippik – 2019-09-06T16:01:02.590

There is a legitimate reason but I'd rather not go into it as it is work related. – BobDoleForPresident – 2019-09-06T16:45:07.070

Perhaps so, but this seems like a somewhat unusual thing to need to do... although my reason for thinking so may be due to ambiguity in the phrasing of the question. Do you want to create these folders on a hard drive and download the files from S3 into them, or are you actually wanting to reorganize the files in S3 itself? On first read, I assumed the latter, which doesn't seem especially useful. – Michael - sqlbot – 2019-09-06T22:41:09.850

Answers

0

In bash, you'd do this

for f in *.jpg; do g="${f%.jpg}"; mkdir "$g"; cp "$f" "$g/$f"; done

hackerb9

Posted 2019-09-06T15:53:24.877

Reputation: 579