폴더의 DateLastModified 속성을 내부 파일의 속성과 일치하도록 재귀적으로 변경합니다.

폴더의 DateLastModified 속성을 내부 파일의 속성과 일치하도록 재귀적으로 변경합니다.

폴더가 여러 개 있고 각 폴더 안에 파일이 들어 있습니다.

구조는 다음과 같습니다.

폴더.No.1
폴더_No_2
폴더 번호 3

그 안에 있는 파일은 다음과 같습니다.

Folder.No.1\My.Movie.1.avi
Folder.No.1\My.Movie.1.txt

Folder_No_2\My_Movie_2.avi
Folder_No_2\My_Movie_2.jpg
Folder_No_2\My_Movie_2.txt

Folder No 3\My Movie 3.avi

보시다시피 일부 폴더 .에는 이름이 포함되어 있고 일부 폴더에는 _공백이 포함되어 있습니다.

한 가지 일관된 요소는 각 폴더가언제나다른 것과 상관없이 .avi 파일을 포함합니다.

Date Modified따라서 폴더에 포함된 .avi 파일의 날짜/시간과 일치하도록 폴더의 날짜/시간을 어떻게 변경할 수 있습니까 ? DateLastModifiedVBScript를 사용하여 내부 파일(자식)을 상위 폴더로 복사하여 이 작업을 수행할 수 있는 방법이 있습니까 ?

지금까지 나는 다음과 같은 작업을 하고 있습니다.

Function Recursion(strDirectory)
On Error Resume Next 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strDirectory)
Set colFiles = objFolder.Files
Dim objFolderShellItem

For Each objFile in colFiles
If UCase(objFSO.GetExtensionName(objFile)) = "AVI" Then
    Set objShell = CreateObject("Shell.Application")
    Set objShellFolder = objShell.NameSpace(strDirectory)
    Set objFolderItem = objFolder.Self
    'folder
    objFolderItem.ModifyDate = objFile.DateLastModified
    'file
    'objShellFolder.Items.Item(objFile.Name).ModifyDate = objFile.DateLastModified
    Wscript.Echo "Date of folder" & objFolder.Name & "was updated" 
End If
Next

For Each folder In objFolder.SubFolders
    Recursion(folder)  '<- recurse here
Next

Set objFso = Nothing
Set objFolder = Nothing
set colFiles = Nothing

End Function




Call Recursion("C:\Temp")

그러나 다음을 사용하여 명령줄에서 호출하면 실패합니다.cscript CopyDateToParent.vbs

이것이 작동하지 않는 원인은 무엇입니까?

답변1

이전 시스템을 사용하고 있다면 다음과 같이 처리했을 것입니다.

더 이상 vbs에서 허용되지 않습니다. 이를 위해서는 컴파일된 언어나 가능한 커널 수준 권한이 필요합니다.

이 사이트의 google powershell은 매우 쉽게 완료되었습니다.

Function Recursion(strDirectory)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strDirectory)
Set colFiles = objFolder.Files
Dim objFolderShellItem
Dim blnFound



blnFound = false
For Each objFile in colFiles
If UCase(objFSO.GetExtensionName(objFile)) = "AVI" Then
    blnFound = true
    dtDateTime = objFile.DateLastModified
    'if you care only about one file, then you can exit for here for performance, or you have to do more logic on keep thing max date for the avi file or min.  you never said.
    ''file
    ''objShellFolder.Items.Item(objFile.Name).ModifyDate = objFile.DateLastModified
End If
Next

For Each folder In objFolder.SubFolders
    if blnFound = true Then
        Set objShell = CreateObject("Shell.Application")
        Set objShellFolder = objShell.NameSpace(strDirectory)''should be parent folder not 'folder' its in
        Set objFolderItem = objShellFolder.Self
        objFolderItem.ModifyDate = dtDateTime   ''no longer possible since around 2010
    End IF
    Recursion(folder)  '<- recurse here
Next

Set objFso = Nothing
Set objFolder = Nothing
set colFiles = Nothing

End Function




Call Recursion("C:\Temp\")

죄송합니다. 도움을 드릴 수 있는 "Microsoft" 시스템이 없습니다.

function GetFiles($path = $pwd) 
{ 
    foreach ($item in Get-ChildItem $path)
    {
        if (Test-Path $item.FullName -PathType Container) 
        {
            $item.LastWriteTime = $dateToChange 
            GetFiles $item.FullName
        } 
        else 
        {   
            if($item.extension.ToUpper() -eq 'AVI')
            {
                $dateToChange = $item.LastWritten
            }
        }
    } 
}

관련 정보