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??
Printable View
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??
Then the file isn't there. :) or it can't be moved. Is it a read-only file?
I'm sorry, I didn't mean read-only. Is the file an exe or dll which is being executed?
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.
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.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
This is how you use the function.
Call f_Move("C:\Source\", "C:\Destination\")
Without useing Nitro code I'm now getting error 58 file already exits, but it is not in the destination directory
'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
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??
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
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.
Does it give you any errors when you move it manually a) in explorer b) in dos?
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.
i do believe the reason would be that you
don't have a file list box called File1
Yes that would be it, I just have a list box, oops.