Networking 在vb6中将网络文件夹中的文件移动到另一个网络文件夹
我想将网络文件夹中的文件移动到另一个网络文件夹,但看起来像是vb6脚本。FileSystemObject对此无能为力Networking 在vb6中将网络文件夹中的文件移动到另一个网络文件夹,networking,vb6,filesystems,Networking,Vb6,Filesystems,我想将网络文件夹中的文件移动到另一个网络文件夹,但看起来像是vb6脚本。FileSystemObject对此无能为力 Set fso = CreateObject("Scripting.FileSystemObject") ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''' DEFINIT
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
有些人认为这是行不通的。。它给出了路径未找到错误。我三次检查了路径和权限,它们都工作正常。是Scripting.FileSystemObject
在网络文件夹中失败,因此我需要一种方法将网络文件夹中的文件传送到另一个文件夹。我怎样才能做到这一点
这里给出了关于我代码的扩展信息
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
Private Sub-netcarryon_Click()
'禁用按钮以阻止假人的双击。。
netcarryon.Enabled=False
FromNetTxt.Enabled=False
ToNetTxt.Enabled=False
NetworkDeleteFolder.Enabled=False
ToNetTxt.Text=Trim(ToNetTxt.Text)“结果\\192.168.1.65\OldPics
FromNetTxt.Text=Trim(FromNetTxt.Text)“结果\\192.168.1.65\Pics
如果正确(FromNetTxt.Text,2)\\,则
fromparentfolder=FromNetText.Text
'继续,直到找到父文件夹
做
fromparentfolder=Mid(fromparentfolder,1,Len(fromparentfolder)-1)
循环直到右边(从父文件夹,1)=“\”,当你到达斜杠“\”停止。
'这是您的文件夹的名称。
fromfolder=Right(fromNetText.Text,Len(fromNetText.Text)-Len(fromparentfolder))
其他的
'您应该给我一个有效的网络路径进行处理。
MsgBox“请输入有效的网络路径…”,vbInformation“不是有效路径!”
'启用因假人而禁用的按钮。。
netcarryon.Enabled=True
FromNetTxt.Enabled=True
ToNetTxt.Enabled=True
NetworkDeleteFolder.Enabled=True
出口接头
如果结束
如果正确(ToNetTxt.Text,2)\\,则
toparentfolder=ToNetTxt.Text
'再次继续,直到找到父文件夹
做
toparentfolder=Mid(toparentfolder,1,Len(toparentfolder)-1)
循环到右边(toparentfolder,1)=“\”,在斜杠“\”处停止。
'没有您的目标文件夹
tofolder=Right(ToNetTxt.Text,Len(ToNetTxt.Text)-Len(toparentfolder))
其他的
“噢!不是有效的目标网络路径吗?你怎么敢。。。
MsgBox“请输入有效的网络路径…”,vbInformation“不是有效的网络路径!”
'再次释放虚拟保护。
netcarryon.Enabled=True
FromNetTxt.Enabled=True
ToNetTxt.Enabled=True
NetworkDeleteFolder.Enabled=True
出口接头
如果结束
'确实要选择这些网络路径吗?
如果MsgBox(“是否确实要将此文件夹中的文件:(“&FromNetTxt.Text&”)传送到此文件夹:(“&ToNetTxt.Text&”)中,vbYesNo,“是否确实?”)=vbNo,则
'反复释放假人保护装置。现在请明智地选择它,好吗!
netcarryon.Enabled=True
FromNetTxt.Enabled=True
ToNetTxt.Enabled=True
NetworkDeleteFolder.Enabled=True
出口接头
如果结束
'添加文件夹脚本
设置fso=CreateObject(“Scripting.FileSystemObject”)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
路径的定义
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set Directory=fso.GetFolder(fromparentfolder&fromfolder)'
设置Moveto=fso.GetFolder(toparentfolder&tofolder)'
设置文件=目录。文件“”
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
多芬特
'目录中的foreach文件
对于文件中的每个文件
filenamehere=fso.GetFileName(文件)
fso.MoveFile文件,Moveto&“\”文件名此处
下一个
'最后,如果一切顺利,并选中删除文件夹!
如果DeleteFolder=1,则
'删除文件夹
fso.DeleteFolder fromNetText.Text,True
如果结束
“你知道这是什么。。
netcarryon.Enabled=True
FromNetTxt.Enabled=True
ToNetTxt.Enabled=True
NetworkDeleteFolder.Enabled=True
MsgBox“程序已成功完成”,vbOKOnly“已完成!”
端接头
在您的第一个示例中,您的对象被称为“fso”,那么当您尝试移动您使用的对象和名为“fsoexist”的对象时,您是否实例化了fsoexist,或者这一行应该这样说
fso.MoveFile File, Moveto & "\" & filenamehere
您可以尝试在不使用FileSystemObject的情况下执行此操作
FileCopy <sourcefile>, <destinationfile>
Kill <sourcefile>
FileCopy,
杀死
终于找到了一个解决方案,我不知道为什么,但使用FileListBox解决了这个问题。
我想我要移动的文件需要先缓存,这应该是由磁盘引起的
Private Sub Timer1_Timer()
Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
'Path of the list box
FromPath = "\\192.168.1.65\OldPics\"
ToPath = "\\192.168.1.50\AllPics\"
FileListBox1.Path = FromPath
If Connection = False Or Finished = False Then
DoEvents
For i = 0 To FileListBox1.ListCount - 1
OurFile = "\" & FileListBox1.List(i)
'For each file in it
If fso.CopyFile(FromPath & OurFile, ToPath & OurFile, True) = True Then
Log "(" & OurFile & ") file has been copied from (" & FromPath & ") to (" & ToPath & "). Success!", False, True, True
Else
''''''''''''''''''''''''''''''' Log Module ''''''''''''''''''''''''''''''''
''Usage: LogString, LogDate, LogTime, DateTimeBeforeLog, DateTimeAfterLog''
''Log "Hello" , False , True , True , False ''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Log "(" & OurFile & ") file could not be copied from (" & FromPath & ") to (" & ToPath & "). Faliure!", False, True, True
End If
Next
Else
End
End If
'''''''''''''''''''''''''' ProgressInc/Dec Module '''''''''''''''''''''''''
'' Usage: ProgressBar, MaxValue, MinValue, Increment, Continues ''
'' Usage: ProgressBar, MaxValue, MinValue, Decrement, Continues ''
'' Default Max = 100 , Min = 1, Inc = 1, False ''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ProgressInc ProgressBar1, 100, 1, 1, True
ProgressDec ProgressBar2, 100, 1, 1, True '
Time = Time + 30 'Do these events every 30 sec
End Sub
我真的不知道为什么会发生这种情况,但对于那些可能与这些磁盘有相同问题的人来说,FileListBox解决了这个问题
编辑:适用于希望使用我的模块的用户
1-ProgressInc/Dec模块
Public Sub ProgressDec(ProgressBarName As ProgressBar, Optional Max As Long, Optional Min As Long, Optional Dec As Long, Optional Continues As Boolean = False)
Dim Recent As Long
On Error GoTo ProgressErr
ProgressBarName.ShowWhatsThis
DoEvents
'Maximum ProgressBar Value
If Max <> 0 Then
ProgressBarName.Max = Max 'If set use it
Else
Max = 100 'If max value is not set then make it 100
ProgressBarName.Max = Max
End If
DoEvents
'Minimum ProgressBar Value
If Min <> 0 Then
ProgressBarName.Min = Min 'If set use it
Else
Min = 1 'If minimum value is not set then make it 1
ProgressBarName.Min = Min
End If
If Dec <> 0 Then Dec = Dec Else Dec = 1
'When the ProgressBar value is at Minimum
'Return to the Maximum value
If Continues = True And ProgressBarName.Value = Min Then
ProgressBarName.Value = Max
End If
'Checkout Recent progress (pre calculate bar value)
Recent = ProgressBarName.Value - Dec
DoEvents
If Recent <= Min Then
'Recent value is lower than or equals to Min value
'to avoid errors caused by this issue value should equal to Min
ProgressBarName.Value = Min
ElseIf Recent > Min Then
'Recent(pre calculated bar value) is higher than Min
'So nothing wrong here, proceed..
ProgressBarName.Value = ProgressBarName.Value - Dec
End If
Exit Sub
ProgressErr:
'ProgressBar is null then create an error report.
MsgBox "With " & Err.Number & " number : '" & Err.Description & "' error occured. "
'MsgBox "ProgressBar is not defined or Cant found the ProgressBar.. Please check the name of ProgressBar and re identify it.", vbCritical, "Unidentified ProgressBar!"
End Sub
Public Sub ProgressInc(ProgressBarName As ProgressBar, Optional Max As Long, Optional Min As Long, Optional Inc As Long, Optional Continues As Boolean = False)
Dim Recent As Long
On Error GoTo ProgressErr
ProgressBarName.ShowWhatsThis
DoEvents
'Maximum ProgressBar Value
If Max <> 0 Then
ProgressBarName.Max = Max 'If set use it
Else
Max = 100 'If max value is not set then make it 100
ProgressBarName.Max = Max
End If
DoEvents
'Minimum ProgressBar Value
If Min <> 0 Then
ProgressBarName.Min = Min 'If set use it
Else
Min = 1 'If min value is not set then make it 1
ProgressBarName.Min = Min
End If
If Inc <> 0 Then Inc = Inc Else Inc = 1
'When the ProgressBar value is at Maximum
'Return to the Minimum value
If Continues = True And ProgressBarName.Value = Max Then
ProgressBarName.Value = Min
End If
'Checkout Recent progress (pre calculate bar value)
Recent = ProgressBarName.Value + Inc
DoEvents
If Recent >= Max Then
'Recent value is higher than or equals to Max value
'to avoid errors caused by this issue Value should equal to Max
ProgressBarName.Value = Max
ElseIf Recent < Max Then
'Recent(pre calculated bar value) is lower than Max
'So nothing wrong here, proceed..
ProgressBarName.Value = ProgressBarName.Value + Inc
End If
Exit Sub
ProgressErr:
'ProgressBar error report.
MsgBox "With " & Err.Number & " number : '" & Err.Description & "' error occured. "
'MsgBox "ProgressBar is not defined or Cant found the ProgressBar.. Please check the name of ProgressBar and re identify it.", vbCritical, "Unidentified ProgressBar!"
End Sub
Dim fso As Scripting.FileSystemObject
Dim logfile As Integer
Dim tarih As String
Function CheckPath(ByVal Path As String) As String
If Right(Trim(Path), 1) = "\" Then
CheckPath = Mid(Trim(Path), 1, Len(Trim(Path)) - 1)
Else
CheckPath = Trim(Path)
End If
End Function
Function Log(LogString As String, Optional LogDate As Boolean, Optional LogTime As Boolean, Optional BeforeLogText As Boolean = False, Optional AfterLogText As Boolean = False) As Boolean
Dim WillBePrinted As String
On Err GoTo LogErr
If BeforeLogText = True Then
'Date Time Before Log
WillBePrinted = "(" & Now & ") " & LogString
ElseIf AfterLogText = True Then
'Date Time After Log
WillBePrinted = LogString & " (" & Now & ")"
Else
'No DateTime Included
WillBePrinted = LogString
End If
Print #logfile, WillBePrinted
Log = True
LogErr:
Log = False
End Function
Function CreateLog(Optional Name As String, Optional Path As String, Optional DateTimeBeforeName As Boolean = False) As Boolean
Dim fso As New Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
logfile = FreeFile
DoEvents
'Name of Log File
If Trim(Name) <> "" Then
Name = Trim(Name)
Else
Name = Trim(App.EXEName)
End If
DoEvents
'Path to Log File
If Trim(Path) <> "" Then
Path = CheckPath(Path)
Else
Path = CheckPath(App.Path)
End If
'If the path does not exists create it!
If fso.FolderExists(Path) = False Then
fso.CreateFolder Path
End If
'DateTimeBeforeName
If DateTimeBeforeName = True Then
DoEvents
FullPath = Path & "\" & TimeMachine & " - " & Name & ".txt"
'if already exists (Highly unlikely while date time is involved)
If (fso.FileExists(FullPath) = True) Then
fso.DeleteFile FullPath, True
Open Path & "\" & TimeMachine & " - " & Name & ".txt" For Output As #logfile
Else
Open Path & "\" & TimeMachine & " - " & Name & ".txt" For Output As #logfile
End If
ElseIf DateTimeBeforeName = False Then
DoEvents
FullPath = Path & "\" & Name & ".txt"
'if already exists (Highly posible while date time is not involved)
If (fso.FileExists(FullPath) = True) Then
fso.DeleteFile FullPath, True
Open Path & "\" & Name & ".txt" For Output As #logfile
Else
Open Path & "\" & Name & ".txt" For Output As #logfile
End If
End If
DoEvents
'Now if everything was successfull
If (fso.FileExists(FullPath) = True) Then
CreateLog = True
Else
CreateLog = False
End If
End Function
Function TimeMachine(Optional OnlyDate As Boolean = False) As String
Dim MyDate, MyTime As String
'Get local date
For Each Part In Split(Date, ".")
'Some times 01.01.2012 is shown as 1.1.2012
'to fix this do a zero check..
If Len(Part) < 3 And Len(Part) > 0 Then Part = Right("00" & Part, 2) Else Part = Part
MyDate = MyDate & "." & Part
Next
'Get local time
For Each Part In Split(Time, ":")
'Some times 01.01.2012 is shown as 1.1.2012
'to fix this do a zero check..
If Len(Part) < 3 And Len(Part) > 0 Then
MyTime = MyTime & "." & Right("00" & Part, 2)
End If
Next
'Clean "." at start
MyDate = Mid(MyDate, 2, Len(MyDate))
MyTime = Mid(MyTime, 2, Len(MyTime))
'Publish
If OnlyDate = True Then
TimeMachine = "Date " & MyDate
Else
TimeMachine = "Date " & MyDate & " Time " & MyTime
End If
End Function
Public Sub ProgressDec(ProgressBarName为ProgressBar,可选最大长度,可选最小长度,可选Dec长度,可选继续布尔值=False)
黯淡的
关于错误转到ProgressErr
ProgressBarName.show这是什么
多芬特
'最大进度条值
如果最大值为0,则
ProgressBarName.Max=Max'如果设置为使用它
其他的
最大值=100'如果未设置最大值,则将其设为100
ProgressBarName.Max=Max
如果结束
多芬特
'最小进度条值
如果最小值为0,则
ProgressBarName.Min=Min'如果设置为使用它
其他的
最小值=1'如果未设置最小值,则将其设为1
ProgressBarName.Min=Min
如果结束
如果Dec为0,则Dec=Dec,否则Dec=1
'当ProgressBar值为M时