Home > Software engineering >  /VBS file mobile inexplicable file already exists
/VBS file mobile inexplicable file already exists

Time:09-17

Write a VBS, want to add a folder below all subfolders documents suffixes all out to arrange, but always said strange file already exists
The code below
 
The Function FilesTree (sPath)
'through a folder all folders folder
The Set oFso=CreateObject (" Scripting. FileSystemObject ")
The Set oFolder=oFso. GetFolder (sPath)
The Set oSubFolders=oFolder. SubFolders

SMoveToPath=oFolder. ParentFolder. Path
SAddName=oFolder. Name
SAddName="-" & amp; sAddName & amp; "] "
If oSubFolders. Count> 0 then
For Each oSubFolder oSubFolders In
Recursive FilesTree (oSubFolder) '
If oSubFolder. Size<50 then
OSubFolder. Delete
End the if
Next
End the if

The Set oFiles=oFolder. Files
For Each oFile oFiles In
SNewName=ofile. Name
SNewName=mid (sNewName, 1, instrrev (sNewName, ". ") - 1) & amp; SAddName & amp; Mid (sNewName, instrrev (sNewName, ""))
Ofile. Name=sNewName
'is the problem here is
'msgbox sMoveToPath& "\ n" & amp; Ofile. Path 'look from msgbox does not exist the nuptial
OFso, movefile ofile path, sMoveToPath
'not in the mobile
'ofile. Move (sMoveToPath)
Next
The Set oFolder=Nothing

The Set oFso=Nothing
End the Function

The set oSubFolders=CreateObject (" Scripting. FileSystemObject "). GetFolder (". "). SubFolders
For Each oSubFolder oSubFolders In
FilesTree (oSubFolder. Path) 'recursive
Next
The Set oSubFolders=Nothing


Due to the large file Numbers (5000 +), large size (about 1 gb), in order to guarantee the speed may not be able to use the Copy + Delete
For help, thank humbly

CodePudding user response:

Baidu had also didn't find the right solution, tell me what kind of keyword search also line

CodePudding user response:

Your sMoveToPath variable values are not correct!

If sMoveToPath represents a "directory", its value in oFso, movefile ofile. The path, sMoveToPath here, must end with "",
But before I see you in the face of the assignment is only this: sMoveToPath=oFolder. ParentFolder. Path
Should be changed to: sMoveToPath=oFolder. ParentFolder. Path & amp; ""

CodePudding user response:

refer to the second floor Chen8013 response:
your sMoveToPath variable values are not correct!

If sMoveToPath represents a "directory", its value in oFso, movefile ofile. The path, sMoveToPath here, must end with "",
But before I see you in the face of the assignment is only this: sMoveToPath=oFolder. ParentFolder. Path
Should be changed to: sMoveToPath=oFolder. ParentFolder. Path & amp; ""

Thank you very much, have been solved!
In addition to trouble by the way, could you tell me to delete has been moving empty folder where is that part of the code are defective? Empty folder complains when an empty folder "oSubFolder does not exist", position error is 13

CodePudding user response:

I am here, as I said in the second floor of the revised, VB6 and VBS are "normal",

CodePudding user response:

reference weixin_42699010 reply: 3/f
Quote: refer to the second floor Chen8013 response:

Your sMoveToPath variable values are not correct!

If sMoveToPath represents a "directory", its value in oFso, movefile ofile. The path, sMoveToPath here, must end with "",
But before I see you in the face of the assignment is only this: sMoveToPath=oFolder. ParentFolder. Path
Should be changed to: sMoveToPath=oFolder. ParentFolder. Path & amp; ""

Thank you very much, have been solved!
In addition to trouble by the way, could you tell me to delete has been moving empty folder where is that part of the code are defective? Empty folder complains when an empty folder "oSubFolder does not exist", position error is 13 line

You use oSubFolder. Size & lt; To judge "empty folder" 50 reliable?

Will there be "hidden, 0 bytes (or a few bytes) file"?
You'd better in the "computer", direct view "folder properties" confirm operation fails directory,

CodePudding user response:

Has been testing out VBS code "error",
But the same situation, VB6 normal execution, VBS will go wrong,

This mistake feel very strange:
FilesTree (oSubFolder path) to deal with the "recursive", delete an empty folder,
And after the "recursive" call returns, in the VBS, oSubFolder the "object" would be the failure!
This is the VBS Bug????
The start of the test, "the innermost" is a file, returns oSubFolder remain "normal",
But why "the innermost" folder is empty, returns oSubFolder would "failure"!!!!!! It's weird!
  • Related