Skip to content

Commit a404c46

Browse files
committed
fix issues with file number incrememnt
- index set to 0 if parse fails - format adds a space even if we are changing existing number
1 parent de73d01 commit a404c46

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,25 @@ private static string IncrementFileName(string path, string filename)
168168
{
169169
string fileWithoutExt = Path.GetFileNameWithoutExtension (filename);
170170
string ext = Path.GetExtension (filename);
171+
string format = "{0} {1}{2}";
171172

172173
int index = 1;
173174

174175
// try extracting the current index from the name and incrementing it
175176
var result = System.Text.RegularExpressions.Regex.Match(fileWithoutExt, @"\d+$");
176177
if (result != null) {
177178
var number = result.Value;
178-
if (int.TryParse (number, out index)) {
179+
int tempIndex;
180+
if (int.TryParse (number, out tempIndex)) {
179181
fileWithoutExt = fileWithoutExt.Remove (fileWithoutExt.LastIndexOf (number));
180-
index++;
182+
format = "{0}{1}{2}"; // remove space from format
183+
index = tempIndex+1;
181184
}
182185
}
183186

184187
string file = null;
185188
do {
186-
file = string.Format ("{0} {1}{2}", fileWithoutExt, index, ext);
189+
file = string.Format (format, fileWithoutExt, index, ext);
187190
file = Path.Combine(path, file);
188191
index++;
189192
} while (File.Exists (file));

0 commit comments

Comments
 (0)