1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
Option Explicit Dim objFSO Dim StrDrive Dim folderobj Dim FromFolder Dim ToFolder Dim FromPath Dim ToPath Dim objSubfolder Dim colSubFolders Dim dicSelFolders Dim FolderToMoveFrom Dim FolderToMoveTo Dim Files Dim OneFile Dim FileInFromFolder Dim Fileset Dim SourceFileName Dim DestFileName Dim FileCount Dim DestFile Dim DocFolderExist StrDrive = "F" FromFolder = "" ToFolder = "Mina dokument" Strdrive=UCase(Left(StrDrive,1)) & ":\" Set objFSO = CreateObject( "Scripting.FileSystemObject" ) Set FromPath = objFSO.GetFolder( StrDrive & FromFolder ) Set ToPath = objFSO.GetFolder( StrDrive & ToFolder ) Set colSubFolders = FromPath.Subfolders Set dicSelFolders = CreateObject( "Scripting.Dictionary" ) 'Folders not to move dicSelFolders.Add "$recycle.bin", "" dicSelFolders.Add "mina dokument", "" dicSelFolders.Add "program", "" 'if folder does not exist on destination drive, ' create it and continue If Not objFSO.FolderExists(StrDrive & "\" & ToFolder) Then 'WScript.Echo "Normal run" objFSO.CreateFolder StrDrive & ToFolder MoveUserFolders() MoveUserFiles() Else 'WScript.Echo "Rename Mina dokument" objFSO.MoveFolder StrDrive & ToFolder, StrDrive & "Gamla " & ToFolder objFSO.CreateFolder StrDrive & ToFolder MoveUserFolders() MoveUserFiles() End If Wscript.Quit Sub MoveUserFolders() For Each objSubfolder in colSubfolders If dicSelFolders.Exists( LCase( objSubfolder.Name ) ) Then 'WScript.Echo "Leaving Folder", objSubfolder.Path Else 'WScript.Echo "Moving Folder", objSubfolder.Path If FromFolder = "" Then FolderToMoveFrom = FromPath & objSubfolder.Name Else FolderToMoveFrom = FromPath & "\" & objSubfolder.Name End If FolderToMoveTo = ToPath & "\" & objSubfolder.Name objFSO.MoveFolder FolderToMoveFrom, FolderToMoveTo End If Next End Sub Sub MoveUserFiles() Set Fileset = FromPath.Files 'if no more subfolders, then go through files For Each OneFile in Fileset SourceFileName = FromPath & "\" & OneFile.name DestFileName = ToPath & "\" & OneFile.name 'if the destination file doesn't exist, 'then copy the sourcefile to the destination folder If Not objFSO.FileExists(DestFileName) Then On Error Resume Next OneFile.Copy DestFileName OneFile.Delete On Error GoTo 0 FileCount = FileCount + 1 'if the destination file already exists Else Set DestFile=objFSO.GetFile(DestFileName) 'then check to see if the source file's last modified date 'is newer than the destination file. If it is, 'then overwrite the destination file with the source file If onefile.DateLastModified > destfile.DateLastModified Then 'turn all file attributes off to copy updated file over older one DestFile.Attributes = 0 On Error Resume Next onefile.Copy DestFileName, True On Error GoTo 0 OneFile.Delete FileCount = FileCount + 1 End If Set destfile=Nothing End If Next End sub |
Copy files to and from Hyper-V Guest
Using the PowerShell cmdlet Copy-VMFile To copy files to a VM using the Copy-VMFile cmdlet, we first have to enable Guest Services under Integration Services for a VM. Luckily, there is a PowerShell one-liner for this:Now we are now ready to copy the file from the...
0 Comments