Option Explicit
Dim My, MySh, Parameters, Fs
Set My = WScript
With My
Set Parameters = .Arguments
If Parameters.Count <= 0 Then
.Quit
End If
Set MySh = .CreateObject("WScript.Shell")
Set Fs = .CreateObject("Scripting.FileSystemObject")
End With
Const vbWq = """"
Dim Pc, Dummy
Dim vbWCrLf
vbWCrLf = vbCrLf & vbCrLf
Dim strTitle, strRoot
strTitle = Fs.GetBaseName(My.ScriptName)
strRoot = Fs.GetParentFolderName(My.ScriptName)
On Error Resume Next
Dim strFolder, strSourceFull, strDate, strMoved
Dim objFiles, objFile
Dim arTargets, inTargets, inTarget, arDates
strFolder = Parameters(0)
If Fs.FileExists(strFolder) Then
MySh.Popup "指定の対象がフォルダではありません", , strTitle, 64
Else
If FD2ar(strFolder, arTargets) Then
If MySh.Popup("フォルダ" & vbWCrLf & strFolder & vbWCrLf & _
"に、格納されている全ファイルに対して、" & vbCrLf & _
"日付フォルダ別分類処理を開始しますか?", , strTitle, 65) = 2 Then
MyQuit
Else
For Each inTargets in arTargets
If TypeName(inTargets) = "Empty" Then
Else
strDate = Split(inTargets(1), " ")(0)
strMoved = DateFolderCreate(strFolder, strDate)
strMoved = Fs.BuildPath(strMoved, inTargets(0))
strSourceFull = Fs.BuildPath(strFolder, inTargets(0))
If Fs.FileExists(strMoved) Then
strMoved = BackupNameCreate(strMoved)
End If
Fs.GetFile(strSourceFull).Move(strMoved)
End If
Next
MySh.Popup Pc + 1 & "コのファイルの" & vbCrLf & "日付フォルダへの分類を完了しました。", , strTitle, 64
End If
Else
MySh.Popup "対象となるファイルが存在していません。", , strTitle, 64
End If
End If
MyQuit
Function BackupNameCreate(strTarget)
Dim strName, strBaseName, strExtention, iResult
strName = Fs.GetFileName(strTarget)
strBaseName = Fs.GetBaseName(strTarget)
strExtention = Replace(strName, strBaseName, "")
iResult = strBaseName & " " & iDT(""," ","",0) & strExtention
BackupNameCreate = Replace(strTarget, strName, iResult)
End Function
Function DateFolderCreate(strRoot, strDates)
Dim arDates, strFolder, iChk, strCN
If Fs.FolderExists(strRoot) Then
arDates = Split(strDates, "/")
strFolder = strRoot
For Each iChk In arDates
strCN = Fs.BuildPath(strFolder, iChk)
If Fs.FolderExists(strCN) Then
Else
Fs.CreateFolder strCN
End If
strFolder = strCN
Next
DateFolderCreate = strFolder
Else
DateFolderCreate = ""
End If
End Function
Function FD2ar(strTarget, arResults)
Dim objFiles, objFile, arTargets()
FD2ar = Fs.FolderExists(strTarget)
If FD2ar Then
Set objFiles = Fs.GetFolder(strTarget).Files
Pc = -1
For Each objFile in objFiles
Pc = Pc + 1
Redim Preserve arTargets(Pc)
arTargets(Pc) = Array(objFile.Name, objFile.DateCreated)
Next
If Pc => 0 Then
arResults = arTargets
Else
FD2ar = False
End If
Else
End If
End Function
Function MyQuit()
Set Fs = Nothing
Set MySh = Nothing
My.Quit
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 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。