Results 1 to 14 of 14

Thread: HELP!!!!!!! How do I move a file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85
    Okay I have added the code and taken out the one line. It works great for the first file, but the second file gives me error number 53 File not Found. What am I doing wrong??
    Using VB6 Still Pluging away

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    Then the file isn't there. or it can't be moved. Is it a read-only file?
    -Shickadance

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    I'm sorry, I didn't mean read-only. Is the file an exe or dll which is being executed?
    -Shickadance

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85
    No all accounts as far as I know. I'm going to check to make sure that it has been closed, but I'm positive that it has.
    Using VB6 Still Pluging away

  5. #5
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Code:
    Sub f_Move(str_Source As String, str_Destin As String)
      Dim lng_FileNumber As Long
      lng_FileNumber = FreeFile
      
      Open str_Destin & "Move.Bat" For Output As #lng_FileNumber
      Print #lng_FileNumber, "Move " & Chr(34) & str_Source & "\*.*" & Chr(34) & " " & Chr(34) & str_Destin & Chr(34)
      Close #lng_FileNumber
      
      DoEvents
      Call Shell(str_Destin & "Move.Bat", vbHide)
      Kill str_Destin & "Move.Bat"
    End Sub
    The only downside to this code is that, it won't move files that already exist in the destination directory. Can you kill the destination directory before you move the files? If not, there is another trick.


    This is how you use the function.
    Call f_Move("C:\Source\", "C:\Destination\")
    Chemically Formulated As:
    Dr. Nitro

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85
    Without useing Nitro code I'm now getting error 58 file already exits, but it is not in the destination directory
    Using VB6 Still Pluging away

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    ..I move my files using this...

    'you can move files with this..no need to delete or anything else
    'to check it out build a new app and add a listbox List1 and
    'a command button Command1
    'copy this code into the code section and run...

    'Once the file is moved it is gone from location 1 and in location 2


    'Check if directory exists
    '-----------------------------------
    Public Function DirExists(ByVal sDirName As String) As Boolean

    Dim sDir As String

    On Error Resume Next

    DirExists = False

    sDir = Dir$(sDirName, vbDirectory)
    If (Len(sDir) > 0) And (Err = 0) Then
    DirExists = True
    End If

    End Function



    Private Sub Command1_Click()

    ' make sure user has selected a file from the list
    If File1.ListIndex >= 0 Then
    Dim strFilePath As String
    Dim strFileName As String

    strFilePath = File1.Path & "\" & File1.FileName
    strFileName = File1.FileName
    End If


    'check for directory..if not in existance then create the
    'directory and then move the file

    Dim SourcePath, Destpath As String
    SourcePath = strFilePath
    Destpath = "c:\MyNewFolder\"

    If DirExists(Destpath) Then 'does the file exist

    Dim sFile$

    sFile = Destpath & strFileName

    Dim fs As Object
    Set fs = CreateObject("Scripting.FileSystemObject")

    'if there is a file in the new dir with file name exit sub
    If fs.fileexists(sFile$) = True Then
    Dim sUser
    sUser = "Sorry, that file exist already." & vbCrLf
    sUser = sUser & vbCrLf
    sUser = sUser & "No need to duplicate...use delete function."
    MsgBox sUser
    Exit Sub
    End If


    Name SourcePath As Destpath & "/" & strFileName
    Set fs = Nothing

    Else

    MkDir ("C:\MyNewFolder")
    'FileCopy SourcePath, DestPath
    Name SourcePath As Destpath & strFileName

    End If

    File1.Refresh

    End Sub

    Private Sub Form_Load()
    File1.Path = "c:\my documents"
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85
    HeSaidJoe,

    I'm trying your code and I'm getting the following error, Compile Error, Can't find project or library. This is happening on File1.path. What am I missing??

    Using VB6 Still Pluging away

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    aburke, youre probably moving a either readonly file, running exe or a file opened by an application in read access. In other words you cannot move the file if you don't remove the readonly attribute, if it's readonly or unlock your harddrive if it's opened or running
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85
    None of the files are read only. Yes I have to open them in Acrobat, but I open them to insert one file into the other one, and then close them before I ever try to move them. The really big kicker is that it all worked under Windows NT and now will not work under Windows 98. The people I'm desgining this for all use 98. If anyone wants the code to see what I'm doing I'll gladly send it to you. I have almost had enough on working on this part, but of course the rest of the project depends on this part working, sort of.
    Using VB6 Still Pluging away

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Does it give you any errors when you move it manually a) in explorer b) in dos?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85
    No to either one. I have also gone in and checked all of the persmissions/attributes and have removed any if there where any there.
    Using VB6 Still Pluging away

  13. #13
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    ...reason is....

    i do believe the reason would be that you
    don't have a file list box called File1
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    85
    Yes that would be it, I just have a list box, oops.
    Using VB6 Still Pluging away

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width