0

I'm going to be as thorough as possible.

I have a folder with a bunch of files, an example of how it looks:

RE-101-00001-EMB-LOD
RE-101-00001-EMB-LOL
RE-101-00002-EMB-LOL
RE-101-00002-EMB-LOD
RE-101-00003-EMB-LOD
RE-101-00003-EMB-LOL

What I'm looking for is a script that will move both the LOL & the LOD files for each pair that share the same 5 digit code (i.e. 00002) into a folder that is named the filename minus the "-LOL" portion.

So just to be clear The script should take both RE-101-00001-EMB-LOL.pdf & RE-101-00001-EMB-LOL.pdf and move them into a folder that will be created named RE-101-00001-EMB

Hope that makes sense. Any help would be appreciated. This task just got dropped on my lap at work and my beginner coding knowledge can't come up with a solution.

  • 2
    BTW: There are a lot of similar questions about tasks like this here on SO. Please use the search bar at the top of the site to search for it. ;-) – Olaf Mar 25 '21 at 22:10
  • Hey @Olaf , thanks for responding. I actually haven't tried anything yet. I've tried googling but my queries haven't turned out any luck. I completely understand that this isn't a free scripting service, I only come here because my experience is more in front-end dev and I have very little exposure to powershell and bash so my questions primarily focus on being directed to the right post. I'm not looking for a free script just guidance to the right answer since my queries that I'm coming up with aren't turning up what I need. – Joshua Huezo Mar 25 '21 at 22:28
  • 1
    Recommendations: make sure you have a backup first, since this sort of thing is easy to mess up. Also, don't use the `mv` (or `cp`) command without its `-i` or `-n` option, to keep it from silently deleting files if there's a name conflict. – Gordon Davisson Mar 26 '21 at 00:12
  • Take a look at [this](https://stackoverflow.com/questions/40130924/iterate-over-files-in-linux-with-different-numbers-in-title) and maybe [this](https://stackoverflow.com/questions/20796200/how-to-loop-over-files-in-directory-and-change-path-and-add-suffix-to-filename). – Gordon Davisson Mar 26 '21 at 00:17
  • I don't think duplicate will be an issue if it is just one level deep inside the directory. Since there can only be one filename at any given directory but yeah better to have backup since it is a good practice and just to be on the safe side. – Jetchisel Mar 26 '21 at 01:10
  • 1
    Take a look at the answer I just posted here: https://stackoverflow.com/questions/66809417/how-to-move-folders-to-other-folders-by-grouping-them-according-to-a-keyword-pre. Its almost the exact same thing you're looking for; just for folders instead of files (which is easy to convert to your problem). Unfortunately, since you haven't provided any real effort at your own code, we can't assist you any further until you do. – Abraham Zinala Mar 26 '21 at 03:12

0 Answers0