0

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?

Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158
  • 1
    I am trying to find that out now. Apparently there is a debug mode so I will see if that helps. – Raphael Rafatpanah Aug 20 '13 at 12:51
  • I don't think there is a way to find the output. I was wondering if the first character being a `/` was the problem, but everything I have tried has not worked. – Raphael Rafatpanah Aug 20 '13 at 12:55
  • Have you tried temporarily structuring your files like they suggest? If so did their regex work? – Martyn Aug 20 '13 at 12:56
  • Well it seems like their Regex does not work either. Hmm, there must be a silly mistake somewhere because Magmi hasn't let me down yet. Thanks for your help. I will be looking into it. – Raphael Rafatpanah Aug 20 '13 at 13:05

2 Answers2

1

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.

MarkG
  • 7,670
  • 2
  • 16
  • 11
1

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.

dweeves
  • 5,525
  • 22
  • 28
  • For the record I have not yet tried this since I had already renamed my image files using Bulk Rename Utility and everything worked fine like that. I will try this on my next set of product imports. – Raphael Rafatpanah Aug 21 '13 at 11:46