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?

  • What purpose would he have for so doing? – DrMoishe Pippik Sep 6 '19 at 16:01
  • There is a legitimate reason but I'd rather not go into it as it is work related. – BobDoleForPresident Sep 6 '19 at 16:45
  • 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 Sep 6 '19 at 22:41
0

In bash, you'd do this

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.