I want to move the file from the directory (2) in the subdirectory (1) (after deleting all files in subfolders (1)) to a subdirectory (1) and delete the folder (2)
For example: I have a folder in disk:
D:/ABC/123/"big" + (with a.jpg;b.jpg;c.jpg..ect)/1.jpg,2.jpg;3.jpg ..ect..
D:/ABC/456/"big" + (with d.jpg;e.jpg;f.jpg..ect)/4.jpg;5.jpg;6.jpg ..ect..
D:/ABC/789/"big" + (with g.jpg;h.jpg;k.jpg..ect)/5.jpg;6.jpg;7.jpg ..ect..
I want delete (a.jpg;b.jpg;c.jpg..ect) in "123" then move (1.jpg,2.jpg;3.jpg ..ect..) in subfolders "big" to "123" then delete "big"
loop all for subfolders in "ABC"
I try :
Dim fso, shl, curdir, folder, file, newfoldername, newfolderpath,subb
Set fso = CreateObject("Scripting.FileSystemObject")
Set shl = CreateObject("WScript.Shell")
curdir = shl.CurrentDirectory
newfoldername = "big"
Sub curdir(Folder)
For Each folder In fso.GetFolder(curdir).SubFolders
For Subfolder in Folder.SubFolders
set subb = fso.GetFolder(curdir).Subfolders
For Each file In folder.Files
MoveFile file.Path, Folder.SubFolders
Next
Next
Next
End Sub
Sub MoveFile(source, destination)
On Error Resume Next
fso.CopyFile source & "\", destination, True ' true = overwrite
If Err Then
WScript.Echo "Error copying " & source & " to " & destination & ": " & Err.Description
WScript.Quit
Else
fso.DeleteFile source, True
WScript.Echo "Delete"
End If
On Error GoTo 0
End Sub
I'm a beginner, help me :)
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFolder In objFSO.GetFolder("D:\ABC").SubFolders
' Delete all of the files in this folder...
For Each objFile In objFolder.Files
objFile.Delete
Next
' Now move all of the files from the "big" subfolder to this folder...
For Each objFile In objFSO.GetFolder(objFolder.Path & "\big").Files
objFSO.MoveFile objFile.Path, objFolder.Path & "\" & objFile.Name
Next
' Finally, delete the "big" subfolder...
objFSO.DeleteFolder objFolder.Path & "\big"
Next
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.