Set Parameters = WScript.Arguments If Parameters.Count <= 0 Then Wscript.Quit End If Set WSHShell = WScript.CreateObject("WScript.Shell") Set Fs = WScript.CreateObject("Scripting.FileSystemObject") Public Target, Source, ThisScript Public Extention, NameOnly, ProcessFolder Dim SourceFolder, SourceFiles, SourceFile, RNameOnly Public Result Dim BackupFile, strFiles, strResult, SettedPF ThisScriptFull = Wscript.ScriptFullName ThisScript = Fs.GetBaseName(ThisScriptFull) For Each SourceFile in Parameters BackupFile = BackupName(SourceFile ) If Extention = "" Then Fs.CopyFolder SourceFile, BackupFile Control = "FolderCopy" Else Fs.CopyFile SourceFile, BackupFile Control = "FileCopy" End If If strResult = "" then strResult = vbCrlf & "● " & ProcessFolder & " " & vbCrlf SettedPF = ProcessFolder Else If SettedPF = ProcessFolder Then Else SettedPF = ProcessFolder strResult = strResult & vbCrlf & vbCrlf & "● " & ProcessFolder & " " & vbCrlf End If End If strResult = strResult & vbCrlf & " " & NameOnly & " " & vbCrlf & vbTab & " ▼ " & vbCrlf & " " & vbTab & RNameOnly & " " & vbCrlf Next Msgbox strResult,,ThisScript & " " & Control Set Fs = Nothing Set WSHShell = Nothing Wscript.Quit Public Function BackupName(SourceName ) Dim FoldersFiles, FoldersCount, FileNamesEx, BlockCount, BackupString FileNamesEx = Split(SourceName,".") BlockCount = UBound(FileNamesEx) If BlockCount > 0 Then Extention = "." & FileNamesEx(BlockCount) Else Extention = "" End If BackupString = " " & iDT(""," ","",0) & Extention FoldersFiles = Split(SourceName,"\") FoldersCount = UBound(FoldersFiles) If Extention = "" Then NameOnly = SourceName ProcessFolder = SourceName RNameOnly = SourceName & BackupString BackupName = RNameOnly Else NameOnly = FoldersFiles(FoldersCount) ProcessFolder = Replace(SourceName, NameOnly, "") BackupName = Replace(SourceName, Extention, BackupString) RNameOnly = Replace(BackupName, ProcessFolder, "") End If End Function Public Function FolderSelector() OnFolder = UpdatesCopy() For Each SourceFile In SourceFolder.SubFolders Set SourceFolder = SourceFile OnFolder = UpdatesCopy() msgbox "2 - サブフォルダ数 - " & OnFolder,,ThisScript If OnFolder = 0 Then Else Set LSourceFolder = SourceFolder For Each tSourceFolder In LSourceFolder.SubFolders Set SourceFolder = tSourceFolder FolderSelector() Set tSourceFolder = SourceFolder Next Set SourceFolder = LSourceFolder End If Next End Function Public Function UpdatesCopy() If SourceFolder.Files.Count = 0 Then If SourceFolder.Name="" Then FolderName = "Root" Else FolderName = SourceFolder.Name End If msgbox "3 - " & FolderName & vbCrLf & "対象フォルダにファイルが無い",,"UpdatesCopy" Else tResult = SourceFolder.name & " - " & SourceFolder.Files.Count & vbCrLf End If For Each SourceFile In SourceFolder.Files tResult = tResult & SourceFile.Path & vbcrlf Next tResult = Replace(tResult & "_", vbcrlf & "_","") If Not tResult = "_" Then msgbox "4 - ファイル一覧" & vbCrLf & tResult,,ThisScript End If UpdatesCopy = SourceFolder.SubFolders.Count End Function Public Function iDT(dSplitter,dtSeparater,tSplitter,Control) Dim nX, nD, nS, strHMS, sResult nX = Now() nD = FormatDateTime(Date(),0) nS = ":" & Split(CStr(FormatDateTime(nX,3)),":")(2) strHMS = FormatDateTime(nX,4) & nS If tSplitter = ":" Then Else strHMS = Replace(strHMS,":",tSplitter) End If sResult = Cstr(Replace(nD,"/",dSplitter)) & "*" & strHMS If Control = 1 Then iDT = Split(sResult,"*") Else iDT = Replace(sResult,"*",dtSeparater) End If End Function
|
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。