Ejemplo n.º 1
0
	TString GetNewNameForFileDigit(const TPath &oldPath, const TString &nameWithoutDigit, __int64 & counter, size_t & leadingZeros, const TPath &pathForRename)
    {
		TString pathWithDigit;
		const int BUFFER_SIZE = 65;
		char buffer[BUFFER_SIZE];
		TString leadingZeroString;

		counter++;
		if (leadingZeros > 0)
		{
			if (LengthOfLong(counter) > LengthOfLong(counter - 1)) //если цифра удленилась
               leadingZeros--;
			for (size_t i = 0; i < leadingZeros; i++)
				leadingZeroString.push_back('0');
		}

		if (_i64toa_s(counter, buffer, BUFFER_SIZE, 10) == 0)
		{
			pathWithDigit = CreatePath(oldPath.GetDirectory(), nameWithoutDigit + leadingZeroString + TString(buffer) + oldPath.GetExtension());
			if(TPath::EqualByNameWithExtension(pathWithDigit, pathForRename))
				return pathForRename.Original();
			if (IsFileExists(pathWithDigit.c_str())) //если такой файл уже есть, то не увеличиваем номер, а добавляем _2
				return GetNewNameForFileAdd(oldPath);
		}
		else
			return GetNewNameForFileAdd(oldPath);
		return pathWithDigit;
    }
Ejemplo n.º 2
0
	TString GetNewNameForFileAdd(const TPath &oldPath, const TPath &pathForRename)
    {
		TString uniquePath;
		const int SIMILAR_PREFIX_SIZE = 16;
		const TChar *SIMILAR_PREFIX_FORMAT = TEXT("_%u");
		TChar buffer[SIMILAR_PREFIX_SIZE];
		unsigned long counter = 2;

		do 
		{
			_stprintf_s(buffer, SIMILAR_PREFIX_FORMAT, counter++);
			uniquePath = CreatePath(oldPath.GetDirectory(), oldPath.GetName(false) + TString(buffer) + oldPath.GetExtension());
			if (TPath::EqualByNameWithExtension(uniquePath, pathForRename))
				break;
		} 
		while (IsFileExists(uniquePath.c_str()));
        return uniquePath;
    }