Question

Magmi is an import tool for some eCommerce software.

I am trying to import images. The problem is that my images are all named "SKU.jpg" and are located in different directories.

Magmi has a tool to solve this using regex.

My problem is coming up with the correct regex expression to make this work.

Note: I have tested my import with manually renamed files, and it works perfectly.

Magmi says if you have similar image names in different directories like this:

thumbs/01.png
standard/01.png

Then use this regex:

re::(.*)/(.*)\.(.*)$::$2_$1.$3

And the files will be renamed like so:

01_thumbs.png
01_standard.png

Now, my files are structured like so:

/images/Headshot/Rectangle/VT08.jpg
/images/FloorShot/Rectangle/VT08.jpg

I was assuming that this regex would work:

re::/(.*)/(.*)/(.*)/(.*)\.(.*)$::$2_$4.$5

to change files like so:

Headshot_VT08.jpg

However, that is not the case.

Is there something I am missing?

Was it helpful?

Solution

try this

re::/(.*?)/(.*?)/(.*?)/(.*)$::$2_$4

no need to separate last one since you'll only want to prefix filename, so you can keep it in a single capture

the ? at the end of the capture is non-greedy (ie: stop capture at first match)

i'll fix the wiki sample since with only one / , the problem didn't arise but the sequence is not easily repeatable.

OTHER TIPS

Try using

 /([^/]*)/([^/]*)/([^/]*)/(.*)\.(.*)  
 so re::/([^/]*)/([^/]*)/([^/]*)/(.*)\.(.*)$::$2_$4.$5

The / at the front is fine, the problem is the (.*)/ part this will match as much as it can so it will match /images/Headshot/Rectangle/ instead of just the first bit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top