1 // FilePathAutoRename.cpp
\r
5 #include "Common/Defs.h"
\r
6 #include "Common/IntToString.h"
\r
8 #include "Windows/FileFind.h"
\r
10 #include "FilePathAutoRename.h"
\r
12 using namespace NWindows;
\r
14 static bool MakeAutoName(const UString &name,
\r
15 const UString &extension, unsigned value, UString &path)
\r
18 ConvertUInt32ToString(value, number);
\r
22 return NFile::NFind::DoesFileOrDirExist(path);
\r
25 bool AutoRenamePath(UString &fullProcessedPath)
\r
28 int dotPos = fullProcessedPath.ReverseFind(L'.');
\r
30 int slashPos = fullProcessedPath.ReverseFind(L'/');
\r
32 int slash1Pos = fullProcessedPath.ReverseFind(L'\\');
\r
33 slashPos = MyMax(slashPos, slash1Pos);
\r
36 UString name, extension;
\r
37 if (dotPos > slashPos && dotPos > 0)
\r
39 name = fullProcessedPath.Left(dotPos);
\r
40 extension = fullProcessedPath.Mid(dotPos);
\r
43 name = fullProcessedPath;
\r
45 unsigned left = 1, right = (1 << 30);
\r
46 while (left != right)
\r
48 unsigned mid = (left + right) / 2;
\r
49 if (MakeAutoName(name, extension, mid, path))
\r
54 return !MakeAutoName(name, extension, right, fullProcessedPath);
\r