Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Adding characters to file name to prevent overwriting?

$
0
0
Hi, I'm making a small application where the user inputs some files in a listbox, and then the files are converted and saved in a folder. However, I still don't know how to make it see if there are files with the same name inside the listbox. So, for example if there are two files called "FileX", it will convert each one and save them, but the last converted one will replace the first one. Also, it will replace any file in that folder with the same name.

I want my application to see if there are files with the same name in that folder, and if there are, add a "(1)" to the last converted file, and if there's already a file with "(1)" in its name, add 1, so it would be a "(2)", "(3)" and so on.

My code is this:

Code:

 
Dim W As IO.StreamWriter
Dim i As Integer
       
        W = New IO.StreamWriter("C:\Myprogram\Converting.bat")

For i = 0 To listbox1.Items.Count - 1

            Dim getname As String
            getname = System.IO.Path.GetFileName(listbox1.Items.Item(i))
         
            'I think the code should be here

            W.WriteLine(*options* & System.IO.Path.GetFileNameWithoutExtension(listbox1.Items.Item(i)) & ".converted" '& some code in here?)
        Next

        W.Close()

Sorry if I don't provide much code, I'm still learning.

Any help would be appreciated.
Thanks in advance.

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>