public string RenameFile(IFileMetaData FileName, int Position, NameExtensionHelper Helper) { Helper.Text = FileName.Name; string numberString; int num = Position + _start; // Format the position number into the correct format switch (_numberFormat) { case NumberingFormat.LowercaseLetters: numberString = StringNumberConversions.NumberToString(num); break; case NumberingFormat.OneZero: numberString = InsertZeros(num, 1); break; case NumberingFormat.TwoZeros: numberString = InsertZeros(num, 2); break; case NumberingFormat.ThreeZeros: numberString = InsertZeros(num, 3); break; case NumberingFormat.NoZeros: goto default; default: numberString = num.ToString(); break; } // This function determines the text format, we will pass it to modify in the NameExtensionHelper Func <String, String> _textFormatFn; switch (_textFormat) { case NumberingTextFormat.NumberText: _textFormatFn = (OldName) => numberString + _text; break; case NumberingTextFormat.NumberTextOldName: _textFormatFn = (OldName) => numberString + _text + OldName; break; case NumberingTextFormat.OldNameTextNumber: _textFormatFn = (OldName) => OldName + _text + numberString; break; case NumberingTextFormat.TextNumber: goto default; default: _textFormatFn = (OldName) => _text + numberString; break; } return(Helper.Modify(_textFormatFn)); }
public string RenameFile(IFileMetaData FileName, int Position, NameExtensionHelper Helper) { Helper.Text = FileName.Name; if (_useRegex) { return(Helper.RegexReplace(_searchRegex, _replaceRegex, _caseSensitive)); } else { return(Helper.Replace(_searchRegex, _replaceRegex, _caseSensitive)); } }
public string RenameFile(IFileMetaData FileName, int Position, NameExtensionHelper Helper) { Helper.Text = FileName.Name; DateTime date; switch (_dateType) { case DateTimeType.Current: date = DateTime.Now; break; case DateTimeType.Created: date = FileName.Created; break; case DateTimeType.Modified: date = FileName.Modified; break; case DateTimeType.PhotoTaken: if (FileName.EXIF == null) { date = FileName.Created; } else { date = FileName.EXIF.DateTaken; } break; default: date = DateTime.Now; break; } string dateString; try { dateString = String.Format("{0:" + _dateFormat + "}", date); } catch (FormatException) { dateString = ""; } return(Helper.Insert(_position, _fromLeft, dateString)); }
/// <summary> /// Perform the renaming /// </summary> /// <param name="FileName">The name of the file</param> /// <param name="Position">Position in the sequence (not used in this class)</param> /// <returns>The new filename</returns> public string RenameFile(IFileMetaData FileName, int Position, NameExtensionHelper Helper) { string newName; Helper.Text = FileName.Name; //NameExtensionHelper nameExtension = NameExtensionHelper.CreateNameExtensionHelper(FileName.Name, _behaviour); if (InsertOrOverwrite) { newName = Helper.Insert(_position, FromLeft, Text); } else { newName = Helper.Overwrite(_position, FromLeft, Text); } return(newName); }
/// <summary> /// Compute the new filename /// </summary> /// <param name="FileName">IFileMetaData of the original file</param> /// <param name="Position">The position in the list of files</param> /// <param name="Helper">A helper to determine what part of the filename to modify</param> /// <returns></returns> public string RenameFile(IFileMetaData FileName, int Position, NameExtensionHelper Helper) { Helper.Text = FileName.Name; switch (_caseType) { case CaseTypes.Lowercase: return(Helper.Modify((s) => s.ToLower())); case CaseTypes.Uppercase: return(Helper.Modify((s) => s.ToUpper())); case CaseTypes.Camelcase: return(Helper.Modify((s) => toCamelCase(s))); case CaseTypes.Sentencecase: goto default; default: return(Helper.Modify((s) => toSentenceCase(s))); } }
string IFileRenamerStrategy.RenameFile(IFileMetaData FileName, int Position, NameExtensionHelper Helper) { return(FileName.Name); }
/// <summary> /// Rename the file /// </summary> /// <param name="FileName">The filename</param> /// <param name="Position">Position in the sequence (not used in this class)</param> /// <returns>The new filename.</returns> public string RenameFile(IFileMetaData FileName, int Position, NameExtensionHelper Helper) { Helper.Text = FileName.Name; return(Helper.RemoveCharacters(_fromPos, _fromLeft, _toPos, _toLeft)); }
/// <summary> /// Rename a file using MP3 data /// </summary> /// <param name="FileName">The file meta data</param> /// <param name="Position">Position in the list</param> /// <param name="Helper">The helper to determine which part of the filename to rename</param> /// <returns>The new filename</returns> public string RenameFile(Model.IFileMetaData FileName, int Position, NameExtensionHelper Helper) { // The idea: scan through the formatstring, character by character until a % is found, // then switch on the next character. Helper.Text = FileName.Name; StringBuilder output = new StringBuilder(); for (int i = 0; i < _formatString.Count(); i++) { if (_formatString[i] != '%') { output.Append(_formatString[i]); } else { if (i == _formatString.Count() - 1) { // we are at the end of the string output.Append('%'); } else { i++; // advance to next character char nextChar = _formatString[i]; switch (nextChar) { case 'a': // artist if (FileName.ID3Tag != null) { output.Append(FileName.ID3Tag.Artist); } break; case 'b': // album if (FileName.ID3Tag != null) { output.Append(FileName.ID3Tag.Album); } break; case 'c': // comment if (FileName.ID3Tag != null) { output.Append(FileName.ID3Tag.Comment); } break; case 'f': // full filename output.Append(FileName.Name); break; case 'g': // genre if (FileName.ID3Tag != null) { output.Append(FileName.ID3Tag.Genre); } break; case 'n': // first part of filename output.Append(Helper.Name); break; case 'p': // position in list output.Append(Position); break; case 't': // title if (FileName.ID3Tag != null) { output.Append(FileName.ID3Tag.Title); } break; case 'x': // extension of file output.Append(Helper.Extension); break; case 'y': // year if (FileName.ID3Tag != null) { output.Append(FileName.ID3Tag.Year); } break; case '%': // escaped % output.Append('%'); break; default: output.Append('%'); output.Append(nextChar); break; } } } } return(Helper.Modify(oldname => output.ToString())); }