Hello.

I want to copy a file from a UNC path (ex: \\comname\dirname\filename.txt) to a local destination (c:\outputdir)

I have no compile errors, but when I run it, it throws an exception (System.IO.DirectoryNotFoundException). I'm absolutely sure the destination existst (it's referencing the destination directory). I've tried doing it with system.io.file.copy(source,dest) and my.computer.filesystem.copyfile(source,dest). Same result either way.

This should be easy, what am I missing??
Thanks

Post the code you are using along with the evaluated value of source and dest for File.Copy() . I have a number of apps that copy from UNC paths and they work OK, except for when the remote machine goes down. Then it throws an IOException . Does your code fail every time or just sometimes? It might be a sharing/permission issue.

Here's the code I'm using:

Dim term As Integer = 1
Dim storenum As String = 2234
Dim sourcefile As String = ("\\t" & term.ToString & "\system3\" & "sys3error.log")
Dim destfile As String = (destination.Text & storenum & "\" & DateTimePicker1.Value.ToString("MMMM") & "-" & DateTimePicker1.Value.ToString("dd") & "\T" & term.ToString & "\Error Log\")
        System.IO.File.Copy(sourcefile, destfile)

destination.text contains a user specified output dir, in this case c:\output\ This produces a value of \\t1\system3\sys3error.log for sourcefile and c:\output\2234\January-14\T1\Error Log\ for destfile when i run it, it thows the exception System.IO.DirectoryNotFoundException, could not find part of path 'c:\output\2234\January-14\T1\Error Log\' I even commented out the destfile variable and change it to c:\testdir\ (which I created first). It throws the same error for that path, every time.

There's a different part of the code that checked which machines are on the network to avoid a network path not found exception, but for this example I'm only talking to \\T1\, and I will probably put a catch in if the file doesn't exist for some reason, but I just want to get the copy part working first.

I can navigate and have read/write access to both source and dest folders.

Thanks

your destfile needs to be a full file path, not just the destination directory. Try c:\output\2234\January-14\T1\Error Log\destination.text for your outfile (i added the filename at the end)

im doing a programme how to copy the files that had been work today or there last modifdate=today but except a certain type of file exemple .tif

im doing a programme how to copy the files that had been work today or there last modifdate=today but except a certain type of file exemple .tif

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.