I'm a relatively new user of Mathematica, and currently using it for image processing of multiple tiff movies. I am also exporting tiff files, and I would like a way of naming my exported files after the corresponding input files.

For example I have a folder that contains two movies called Movie1.tiff and Movie2.tiff, I start with this code:

raw = FileNames["*.tif", SystemDialogInput["Directory"]];

movies = Import[#] & /@ raw;

I have created function f that processes the movies, so in order to export I use the following code, having already specified the directory 'dir':

     dir <> DateString["Time"] <> "timepoint" <> ToString[i] <> "_" <> 
      ".tif", f[#[[i]]]], {i, 1, Length[#]}] & /@ movies;

The reason for including DateString is because otherwise, the first movie file exports "timepoint1.tiff, timepoint2.tiff, timepoint3.tiff..." etc, but then the second movie exports with the same filenames so it overwrites.

I would be very grateful if someone could suggest a better way of naming the two sets of exported tiff files, preferentially including the filename of the imported files, for example: "Movie1_timepoint1.tiff, "Movie1_timepoint2.tiff..." etc.

Apologies for the long question! Thank you very much in advance!

  • 2
    $\begingroup$ You can use the information that is stored raw. $\endgroup$
    – Karsten7
    Commented Dec 8, 2015 at 14:02

1 Answer 1


you'll need to add the information of the filenames to the Export command, because your movies contains only the video data but no filenames. The filenames are still contain as String in your raw. To improve your code in a simple way I would create a matrix where the data of movies and raw are aligned e.g. Transpose[{movies,raw}]

Then your code should be changed to

     dir <> #[[i, 2]] <> DateString["Time"] <> "timepoint" <> ToString[i] <>"_" <> .tif",
     f[#[[i,1]]]], {i, 1, Length[#]}] & /@ Transpose[{movies,raw}];

With #[[i, 2]] accessing the second row (and thus the names of the videos) and with #[[i,1]] accesing the video data.

One more tipp. If the length of the images is bigger than 9 the way you are trying to work will provide you with a not so nice structure in e.g. the Windows explorer as (short name) filename1.dat will be followed first by filename10.dat and then only by filename2.dat

To prevent this from happening you can use the following trick: add a large enough number (larger than the number of elements you want to export) to your i, e.g. 1000+i convert this to String and remove the first character: StringDrop[ToString[1000+i],1] then your file names will be named as






and so on. In your code this would be then

     dir <> #[[i, 2]] <> DateString["Time"] <> "timepoint" <> 
      StringDrop[ToString[1000+i],1] <>"_" <> .tif",
     f[#[[i,1]]]], {i, 1, Length[#]}] & /@ Transpose[{movies,raw}];

Hope this helps

  • 1
    $\begingroup$ for StringDrop[ToString[1000+i],1], try IntegerString[i, 10, 3] $\endgroup$
    – dwa
    Commented May 3, 2017 at 6:15
  • $\begingroup$ @dwa: thanks I wasn`t aware of that command $\endgroup$
    – Quit007
    Commented Nov 7, 2017 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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