I want to move my files in a network folder to another network folder but seems like vb6 Scripting.FileSystemObject cannot do anything about this..
Set fso = CreateObject("Scripting.FileSystemObject")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''' DEFINITION FOR PATH ''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set Directory = fso.GetFolder(fromparentfolder & fromfolder) ''
Set Moveto = fso.GetFolder(toparentfolder & tofolder) ''
Set Files = Directory.Files ''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DoEvents
'foreach file in directory
For Each File In Files
filenamehere = fso.GetFileName(File)
fso.MoveFile File, Moveto & "\" & filenamehere
Next
Some how this does not work.. It gives the path not found error. I triple checked the path and permissions they are all working fine. Its the Scripting.FileSystemObject that fails at the network folders so i need a way trough this to carry my files in a network folder to another one. How can i achive this?
Given extended info about my code down here..
Private Sub netcarryon_Click()
'Disable button to block double clicking for the dummies..
netcarryon.Enabled = False
FromNetTxt.Enabled = False
ToNetTxt.Enabled = False
NetworkDeleteFolder.Enabled = False
ToNetTxt.Text = Trim(ToNetTxt.Text) 'Result \\192.168.1.65\OldPics
FromNetTxt.Text = Trim(FromNetTxt.Text) 'Result \\192.168.1.65\Pics
If Right(FromNetTxt.Text, 2) <> "\\" Then
fromparentfolder = FromNetTxt.Text
'Keep going till u find parent folder
Do
fromparentfolder = Mid(fromparentfolder, 1, Len(fromparentfolder) - 1)
Loop Until Right(fromparentfolder, 1) = "\" 'When u reach SLASH "\" stop.
'There is the name of your folder.
fromfolder = Right(FromNetTxt.Text, Len(FromNetTxt.Text) - Len(fromparentfolder))
Else
'You should give me a valid network path to process.
MsgBox "Please enter a valid network path..", vbInformation, "Not a valid path!"
'Enable the button that is disabled cause of dummies..
netcarryon.Enabled = True
FromNetTxt.Enabled = True
ToNetTxt.Enabled = True
NetworkDeleteFolder.Enabled = True
Exit Sub
End If
If Right(ToNetTxt.Text, 2) <> "\\" Then
toparentfolder = ToNetTxt.Text
'Again keep going until you find the parent folder
Do
toparentfolder = Mid(toparentfolder, 1, Len(toparentfolder) - 1)
Loop Until Right(toparentfolder, 1) = "\" 'Stop at SLASH "\".
'There is ur target folder
tofolder = Right(ToNetTxt.Text, Len(ToNetTxt.Text) - Len(toparentfolder))
Else
'Oh! Not a valid target network path ha? How dare you...
MsgBox "Please enter a valid network path..", vbInformation, "Not a valid network path!"
'Again release dummy protection.
netcarryon.Enabled = True
FromNetTxt.Enabled = True
ToNetTxt.Enabled = True
NetworkDeleteFolder.Enabled = True
Exit Sub
End If
'You sure you wanna choose these network paths?
If MsgBox("Are you sure you want to carry files in this folder : (" & FromNetTxt.Text & " )to this folder : (" & ToNetTxt.Text & ")?", vbYesNo, "Are you sure?") = vbNo Then
'Release dummy protection again and again. Now please chose it wisely, would ya!
netcarryon.Enabled = True
FromNetTxt.Enabled = True
ToNetTxt.Enabled = True
NetworkDeleteFolder.Enabled = True
Exit Sub
End If
'Add the folder script
Set fso = CreateObject("Scripting.FileSystemObject")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''' DEFINITION FOR PATH ''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set Directory = fso.GetFolder(fromparentfolder & fromfolder) ''
Set Moveto = fso.GetFolder(toparentfolder & tofolder) ''
Set Files = Directory.Files ''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DoEvents
'foreach file in directory
For Each File In Files
filenamehere = fso.GetFileName(File)
fso.MoveFile File, Moveto & "\" & filenamehere
Next
'At the end if everthing went fine and delete folder checked!
If DeleteFolder = 1 Then
'Delete folder
fso.DeleteFolder FromNetTxt.Text, True
End If
'You know what this is..
netcarryon.Enabled = True
FromNetTxt.Enabled = True
ToNetTxt.Enabled = True
NetworkDeleteFolder.Enabled = True
MsgBox "Program finished successfully.", vbOKOnly, "Finished!"
End Sub
Found a solution at last I’m not really sure why but using FileListBox solves this problem.
I guess the files i’m trying to move needs to be cached first it should be caused by the disk.
I really dont know why this happens but for those who may have the same problem with these kinda disks FileListBox solves it.
Edit: for those who would like to use my modules..
1- ProgressInc/Dec Module
2- My own Log Module
You may ask “why there is a TimeMachine function here?” I dont know! i just wanted to have my own TimeMachine. Just puzzling with my self.