Why is this file.copy not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Saabster

    #1

    Why is this file.copy not working

    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("Directo ry " & path & " Found!")
    File.Copy(strSe nder, path & strTargetFile) ' Now copy
    the file
    End If
    Catch
    Console.WriteLi ne("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

  • Michael M.

    #2
    Re: Why is this file.copy not working

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

    Just a stab in the dark.

    Michael.
    "Saabster" <cbobchin@sbcgl obal.netwrote in message
    news:1168045726 .845614.278050@ 38g2000cwa.goog legroups.com...
    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("Directo ry " & path & " Found!")
    File.Copy(strSe nder, path & strTargetFile) ' Now copy
    the file
    End If
    Catch
    Console.WriteLi ne("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
    >

    Comment

    • Rad [Visual C# MVP]

      #3
      Re: Why is this file.copy not working

      On Sat, 6 Jan 2007 02:15:52 -0000, Michael M. wrote:
      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:\Destin ation\One.xls"

      it will do

      File.Copy("One. xls","C:\Destin ationOne.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("Na me of your file") and
      Directory.Exisi ts("Name of your directory") to check for the existence of
      files and directories rather than instr

      --
      Bits.Bytes

      Comment

      • Phill W.

        #4
        Re: Why is this file.copy not working

        Saabster wrote:
        File.Copy(strSe nder, path & strTargetFile) ' Now copy
        Instead of

        File.Copy(strSe nder, path & strTargetFile)

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

        File.Copy(strSe nder, Path.Combine( path, strTargetFile ) )

        which takes care of this for you.

        HTH,
        Phill W.

        Comment

        • Zukester

          #5
          Unable to stretch objects

          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

          Comment

          • Saabster

            #6
            Re: Why is this file.copy not working

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

            Craig
            Saabster wrote:
            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("Directo ry " & path & " Found!")
            File.Copy(strSe nder, path & strTargetFile) ' Now copy
            the file
            End If
            Catch
            Console.WriteLi ne("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

            Comment

            Working...