From: Kerem Gümrükcü on
Hi,

i am looking for some API that will give me the next
available file/folder name if the file/folder aleady
exists. Example: you have a file named "New Text.txt",
o the operating system suggests here "New Text(1).txt"
if you create a new file within the shell. Is there any API
that could give me the next available name for a file if
i provide a filename as input? I guess its some shell interface
or function, but i could not find anything so far,...

Thanks in advance,...

Regards

Kerem

--
-----------------------
Beste Gr�sse / Best regards / Votre bien devoue
Kerem G�mr�kc�
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------

From: Jeff Gaines on

On 27/01/2010 in message <uogn98ynKHA.3636(a)TK2MSFTNGP06.phx.gbl> Kerem
G�mr�kc� wrote:

>Hi,
>
>i am looking for some API that will give me the next
>available file/folder name if the file/folder aleady
>exists. Example: you have a file named "New Text.txt",
>o the operating system suggests here "New Text(1).txt"
>if you create a new file within the shell. Is there any API
>that could give me the next available name for a file if
>i provide a filename as input? I guess its some shell interface
>or function, but i could not find anything so far,...

I use the following for files:

internal static string GetUniqueFilePath(string filePathIN)
{
int count = 1;
string result = filePathIN;

FileInfo fInfo = new FileInfo(result);
if (fInfo.Exists)
{
do
{
result = filePathIN + "." + count.ToString("0000");
count++;
fInfo = new FileInfo(result);
}
while (fInfo.Exists);
}
return result;
}

It adds the number at the end so you would need to tweak it a bit to put
the number in a different place.

--
Jeff Gaines Dorset UK
There are 3 types of people in this world. Those who can count, and those
who can't.
From: Kerem Gümrükcü on
Hi Jeff,

thanks a lot, thats nice, but i already have something
like that, but i will "follow" the Microsoft Windows
naming scheme to make sure that evrything is fine.
I dont want to reinvent the wheel if there is such a
function already build into windows itself,...if not,
i have to go the hard way,...

Regards

Kerem

--
-----------------------
Beste Gr�sse / Best regards / Votre bien devoue
Kerem G�mr�kc�
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------

"Jeff Gaines" <jgaines_newsid(a)yahoo.co.uk> schrieb im Newsbeitrag
news:xn0gpmx4t13hyhn001(a)msnews.microsoft.com...
> On 27/01/2010 in message <uogn98ynKHA.3636(a)TK2MSFTNGP06.phx.gbl> Kerem
> G�mr�kc� wrote:
>
>>Hi,
>>
>>i am looking for some API that will give me the next
>>available file/folder name if the file/folder aleady
>>exists. Example: you have a file named "New Text.txt",
>>o the operating system suggests here "New Text(1).txt"
>>if you create a new file within the shell. Is there any API
>>that could give me the next available name for a file if
>>i provide a filename as input? I guess its some shell interface
>>or function, but i could not find anything so far,...
>
> I use the following for files:
>
> internal static string GetUniqueFilePath(string filePathIN)
> {
> int count = 1;
> string result = filePathIN;
>
> FileInfo fInfo = new FileInfo(result);
> if (fInfo.Exists)
> {
> do
> {
> result = filePathIN + "." + count.ToString("0000");
> count++;
> fInfo = new FileInfo(result);
> }
> while (fInfo.Exists);
> }
> return result;
> }
>
> It adds the number at the end so you would need to tweak it a bit to put
> the number in a different place.
>
> --
> Jeff Gaines Dorset UK
> There are 3 types of people in this world. Those who can count, and those
> who can't.

From: Kerem Gümrükcü on
No need to reinvent the wheel:

[PathMakeUniqueName]
http://msdn.microsoft.com/en-us/library/bb776476%28VS.85%29.aspx

But only works >= XP

Regards

Kerem

--
-----------------------
Beste Gr�sse / Best regards / Votre bien devoue
Kerem G�mr�kc�
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------

"Kerem G�mr�kc�" <kareem114(a)hotmail.com> schrieb im Newsbeitrag
news:e0MOkn0nKHA.4436(a)TK2MSFTNGP02.phx.gbl...
> Hi Jeff,
>
> thanks a lot, thats nice, but i already have something
> like that, but i will "follow" the Microsoft Windows
> naming scheme to make sure that evrything is fine.
> I dont want to reinvent the wheel if there is such a
> function already build into windows itself,...if not,
> i have to go the hard way,...
>
> Regards
>
> Kerem
>
> --
> -----------------------
> Beste Gr�sse / Best regards / Votre bien devoue
> Kerem G�mr�kc�
> Latest Project: http://www.pro-it-education.de/software/deviceremover
> Latest Open-Source Projects: http://entwicklung.junetz.de
> -----------------------
>
> "Jeff Gaines" <jgaines_newsid(a)yahoo.co.uk> schrieb im Newsbeitrag
> news:xn0gpmx4t13hyhn001(a)msnews.microsoft.com...
>> On 27/01/2010 in message <uogn98ynKHA.3636(a)TK2MSFTNGP06.phx.gbl> Kerem
>> G�mr�kc� wrote:
>>
>>>Hi,
>>>
>>>i am looking for some API that will give me the next
>>>available file/folder name if the file/folder aleady
>>>exists. Example: you have a file named "New Text.txt",
>>>o the operating system suggests here "New Text(1).txt"
>>>if you create a new file within the shell. Is there any API
>>>that could give me the next available name for a file if
>>>i provide a filename as input? I guess its some shell interface
>>>or function, but i could not find anything so far,...
>>
>> I use the following for files:
>>
>> internal static string GetUniqueFilePath(string filePathIN)
>> {
>> int count = 1;
>> string result = filePathIN;
>>
>> FileInfo fInfo = new FileInfo(result);
>> if (fInfo.Exists)
>> {
>> do
>> {
>> result = filePathIN + "." + count.ToString("0000");
>> count++;
>> fInfo = new FileInfo(result);
>> }
>> while (fInfo.Exists);
>> }
>> return result;
>> }
>>
>> It adds the number at the end so you would need to tweak it a bit to put
>> the number in a different place.
>>
>> --
>> Jeff Gaines Dorset UK
>> There are 3 types of people in this world. Those who can count, and those
>> who can't.
>
From: Stefan Kuhr on
Hi Kerem,

On 1/27/2010 10:00 AM, Kerem G�mr�kc� wrote:
> Hi,
>
> i am looking for some API that will give me the next
> available file/folder name if the file/folder aleady
> exists. Example: you have a file named "New Text.txt",
> o the operating system suggests here "New Text(1).txt"
> if you create a new file within the shell. Is there any API
> that could give me the next available name for a file if
> i provide a filename as input? I guess its some shell interface
> or function, but i could not find anything so far,...
>

Even if there is such a thing, what value would it give to you? Once you
had that "next available file/folder name" and just before you can
create it, your program can be preempted and someone else can calculate
this file/folder and create it, so what value will your prior call to
this imaginary function have?. Having a function that does this as an
API is subject to race conditions, so it is per se useless, unless
tightly coupled with a file/foldeer creation call. The only sure thing
is a function that tries to *create* the next possible file/folder.

You mentioned PathMakeUniqueName, I never used that, does it only
"suggest" the file name or does it create the file as well? If it
doesn't create the file name, you will have to use that in a loop until
a combination of the result of both PathMakeUniqueName and CreateFile
succeed. BTW: MSDN online says that PathMakeUniqueName is suppported on
W2K as well.

--
S