Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to copy and rename a file

Here is what I've tried to do so far(and it's obviously does'nt work):

VB
.
.
.
Else
        Dim diMyDir As New DirectoryInfo(My.Settings.ImgOutput + "/" + IDnumU.Text)
        diMyDir.Create()
        diMyDir.Attributes = FileAttributes.Hidden
        For c As Integer = 0 To lstFiles.Items().Count
            System.IO.File.Copy(lstFiles.Items(c).ToString(), diMyDir.FullName.ToString() & "/" & c.ToString())

        Next
    End If

End Sub


I must copy the file, AND THEN rename it, because this program is handling the Phone's file.

It found the file path that I want but it does'nt copy it, it displays a Runtime error name:

NotSupportedException was unhandled

Thank you in advance, Tsahi.
Posted
Updated 16-Sep-11 5:39am
v2

Your problem is that lstFiles.Items(c) is of the type ListViewItem. Thus you'll have to use the property Text to retrieve the path. ToString() will return something that will contain the type information including the actual path information and thus will not be suitable for your purposes.

I hope this helps you clear the issue!

[Edit]
This small code sample may be in C#, but it works like charm in copying all the files from D:\Test\Test into the subdirectory D:\Test\Test\Test where they are stored as 0, 1, 2, etc. :

C#
static void Main(String[] args)
{
    string[] entries = Directory.GetFiles(@"d:\Test\Test\");
    for(int c = 0; c < entries.Length; c++)
    {
        System.IO.File.Copy(entries[c], String.Format(@"D:\Test\Test\Test\{0}",  c.ToString()));
    }
    Console.ReadLine();
}


Maybe a piece of working code will show you where you went wrong!
[/Edit]

—MRB
 
Share this answer
 
v3
Comments
tsahi-al 16-Sep-11 12:09pm    
Thnx for replying :), but unfortunetly it had no effect on the runtime error >~<

Tsahi.
Manfred Rudolf Bihy 16-Sep-11 12:30pm    
See the update to my solution if you please!
tsahi-al 16-Sep-11 12:56pm    
Mate thanx for helping but i know C# only at the Console level, I have no clue what:

<pre>entries[c], String.Format(@"D:\Test\Test\Test\{0}",</pre>

means

could u please explain the code with side notes?
VB
Dim dir as new DirectoryInfo(myfoldername);
Dim files as FileInfo() = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly)


At this point, you can iterate through the files found in the specified folder.

VB
foreach file as string in files
    ' do something with "file" 

Next
 
Share this answer
 
Comments
tsahi-al 16-Sep-11 8:06am    
The prtoblem is not getting the files or creating a new directory,
im struggeling with the copying and than renaming function,
I've tryied to use the "copy" command but it dose'nt work. it gives me a Runtime error as ive allready Wrote above.
Reiss 16-Sep-11 8:15am    
What are the values stored in lstFiles.Items(c).ToString() and c.ToString()
tsahi-al 16-Sep-11 8:42am    
File's Path's, and lots of them they are all in jpg, jpeg or bmp Format
Tsahi,

According to MSDN documentation[^] for the System.IO.File.Copy method, when you get a NotSupportedException exception, it means "sourceFileName or destFileName is in an invalid format. "

Have you done debugging to ensure that you have valid file names listed? If possible, can you edit your question with the Visual Studio output of the error message after you have ensured that the file names are indeed valid.

Hogan
 
Share this answer
 
Yesterday ive founed the Solution it was a stupad mistake >~<<br mode="hold" />
I've changed all the
lstFiles.Items(c).ToString()


TO

lstFiles.Items(c).Text()


EXCEPT one row

So now its working, but i need help with the DB, could some one please link me to a DB tuturial and commans please?

thank you for helping me.

and special thanx for Manfred R. Bihy for recotnigzing the problem.

tsahi.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900