2013-04-08 4 views
-7

Windows 7에서 현재 디렉토리와 그 하위 디렉토리, 하위 하위 디렉토리 등의 모든 파일을 특정 LastWrite YEAR과 함께 상대 경로로 새 디렉토리로 이동하려면 PowerShell을 사용하고 싶습니다.특정 연도의 파일을 상대 경로와 함께 새 디렉터리로 이동하는 방법?

누군가가 나를 쓸 필요가 PowerShell 라인 코드 사용할 수 있습니까?

+2

[당신이 시도 무엇?] (http://mattgemmell.com/2008/12/08/what-을 실행 소스로 CD 무엇 u는 필요하다 have-you-tried /) – nimizen

답변

0

당신은 다른

예를 하나 개의 경로에서 파일을 이동 Move-Item 기능을 사용할 수 있습니다 :

Move-Item 'c:\YourFolder\*' 'c:\DestinationFolder'

대상 폴더 (*)에 폴더에있는 모든 파일을 이동합니다.

where-object 기능으로는 파이프를해야합니다 특정 날짜에서 파일을 이동하려면 다음

예 :

Get-ChildItem 'C:\folder' | where-object {$_.lastwritetime.Year -eq 2013} |
Move-Item -destination 'c:\DestinationFolder'

여기 http://technet.microsoft.com/en-us/library/ee176910.aspx

+1

특정 연도와 일치하면 where 조건을'$ _. lastwritetime.Year -eq 2008'과 같이 변경합니다. – Richard

0

이에 대한 해결책이다 상대 경로를 유지하라. DIR은 다음

$files = Get-ChildItem -Recurse -File | where {$_.LastWriteTime.Year -eq 2012} 

를 업데이트하고

$baselength = (Get-Location).Path.Length + 1 
    $destDir = 'G:\dest' 

    $files = Get-ChildItem -Recurse -File | where {$_.LastWriteTime.Year -eq 2012} 

    $files | foreach { 
     Write-Verbose "moving $_.fullname"  
     $dest = Join-Path $destDir $_.FullName.Substring($baselength) 
     if (-not (Test-Path (Split-Path $dest))) 
     { 
      New-Item -ItemType directory -Path (Split-Path $dest) | Out-Null 
     } 
     Move-Item $_.FullName $dest -Force 
    } 
관련 문제