Why is this file.copy not working

  • Thread starter Thread starter Saabster
  • Start date Start date
S

Saabster

Hi all,

It's always the simple stuff that trips you up I guess. Here is the
issue I'm dealing with.

I have a folder with 1400 excel files that I need to move to another
location. Since each file has to go in to a particular target folder I
decided that writing a program to move the files is they way to go.

I've got all but this last piece down. and for the life of me I can't
understand why the file.copy statement will not copy the file.

Try
If InStr(path, strTargetPath) Then 'We Found the Correct
Target Folder
MsgBox("Directory " & path & " Found!")
File.Copy(strSender, path & strTargetFile) ' Now copy
the file
End If
Catch
Console.WriteLine("Error.")
End Try

The copy appears to work when I step through the code, but when I check
the target folder the copied file is not there.

Can anyone tell me why this is happening (or not as the case is)? I
have verified that the source file exists, as well as the target folder
and there is no file with the same name in the target.

Please help. this is the last piece of the puzzle.

Thanks

Craig
 
Try adding a "\"
after path if its not there allready.

Just a stab in the dark.

Michael.
 
Try adding a "\"
after path if its not there allready.

Just a stab in the dark.

Michael.


Like Michaels says, you might need to add a '\' after the path or instead
of doing

File.Copy("One.xls","C:\Destination\One.xls"

it will do

File.Copy("One.xls","C:\DestinationOne.xls"

in which case the file will be copied and end up in the parent folder from
where you inteded it to go.

Also you might want to use File.Exists("Name of your file") and
Directory.Exisits("Name of your directory") to check for the existence of
files and directories rather than instr
 
Saabster said:
File.Copy(strSender, path & strTargetFile) ' Now copy

Instead of

File.Copy(strSender, path & strTargetFile)

which is vulnerable to missing (or multiple) '\'s, try

File.Copy(strSender, Path.Combine( path, strTargetFile ) )

which takes care of this for you.

HTH,
Phill W.
 
Hi:

Newbie here. Was in the middle of doing a
series of forms with labels and buttons and,
all of a sudden, I could no longer stretch
any objects on some forms. I did not
consciously do anything to cause this. Did I
accidentally type a keystroke to lock
everything? Right click and "lock" is not on
anything. I have closed the file and
program, reopened it and the like. Looked at
the MSDN site, etc. I have looked at all
property sheets from those of the object, the
form and the application.

Any ideas?

Also, in VB 6 there was an "MDI Child" yes/no
on all forms..... I made an MDI form, but how
do I add forms to it?

Thanks So Much,

BZ
 
Thanks All, it was the missing "\" that was the problem. Phil, I like
your solution. Consider it implemented.
 
Back
Top