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