PC · IT · DB/PC

[PowerShell] Get-ChildItem 수정 후 30분 지난 파일 찾기 (forfiles 시간 단위 설정 대체)

뿌레도 2023. 9. 15. 23:50
728x90
[PowerShell] Get-ChildItem 수정 후 30분 지난 파일 찾기 (forfiles 시간 단위 설정 대체)

 

글 메인 사진

#Get-ChildItem #Where-Object #ForEach-Object

 명령프롬프트(cmd)의 forfiles에서 /D 옵션은 날짜(dd)를 기준으로 동작하기 때문에 시간 단위(시, 분, 초)로 조작하기가 매우 어렵습니다. 명령 프롬프트는 주로 파일 및 디렉토리 관리, 프로세스 실행 등의 기본적인 작업에 사용되기 때문에 시간과 관련된 복잡한 작업은 주로 프로그래밍 언어나 스크립트를 사용하여 처리하는 것이 더 효율적입니다.

 

 

728x90

 


명령 프롬프트에서 시간을 다루기 어려운 이유

  1. 시간 형식의 제한: 명령 프롬프트에서는 시간을 표현하는 데 사용할 수 있는 형식이 제한적입니다. 일반적으로 시간은 문자열로 표현되며, 날짜 및 시간 간의 계산이나 비교를 수행하기 어렵습니다.
  2. 시간 관련 기능의 부족: 명령 프롬프트에는 시간을 다루기 위한 특별한 내장 함수나 명령어가 제공되지 않습니다. 따라서 시간을 다루기 위해서는 외부 도구나 프로그래밍 언어를 사용해야 합니다.
  3. 시간대 및 지역 설정의 한계: 명령 프롬프트는 시스템의 시간대 및 지역 설정을 사용합니다. 따라서 시간대 변경이나 다른 지역의 시간을 다루는 것은 어렵습니다.
  4. 정밀도의 한계: 명령 프롬프트에서는 일반적으로 시간을 초 단위로 다룹니다. 따라서 밀리초나 마이크로초와 같은 더 작은 단위의 시간을 다루기 어렵습니다.

 

1. Get-ChildItem -Path "경로"

 "경로"(-Path)에 존재하는 폴더 및 파일 찾기

 

Get-ChildItem -Path "C:\trivia-korea"

결과값 d----- 은 디렉터리(경로)이고 -a----은 파일이다.

 

결과화면 : Get-ChildItem -Path "경로"

 

 

 

2. Get-ChildItem -Path "경로" -Filter "파일명 조건" -Recurse

 "경로"(-Path)에 존재하는 폴더 및 파일 찾기 + .txt 파일 (-Filter) + 하위폴더 포함(-Recurse)

 

Get-ChildItem -Path "C:\trivia-korea" -Recurse -Filter "*.txt"

 

결과화면 : Get-ChildItem -Path "경로" -Filter "파일명 조건" -Recurse

 

 

 

 

 

 

 

 

 

3. Get-ChildItem -Path "경로" -Filter "파일명 조건" -Recurse | Where-Object { 조건문 }

 "경로"(-Path)에 존재하는 폴더 및 파일 찾기 + .txt 파일 (-Filter) + 하위폴더 포함(-Recurse) + 조건 ( 마지막 수정일자가 현재시간 - 30분 보다 작은 == 수정한지 30분이 지난)

 

Get-ChildItem -Path "C:\trivia-korea" -Filter "*.txt" -Recurse | `
Where-Object { $_.LastWriteTime -lt (Get-Date).AddMinutes(-30) }

 

 

 

 

4. Get-ChildItem -Path "경로" -Filter "파일명 조건" -Recurse | Where-Object { 조건문 } | ForEach-Object {표현 방식}

 "경로"(-Path)에 존재하는 폴더 및 파일 찾기 + .txt 파일 (-Filter) + 하위폴더 포함(-Recurse) + 조건 ( 마지막 수정일자가 현재시간 - 30분 보다 작은 == 수정한지 30분이 지난) ==> 표현 방식 (풀 네임)

 

Get-ChildItem -Path "C:\trivia-korea" -Recurse -Filter "*txt" | `
Where-Object { $_.LastWriteTime -lt (Get-Date).AddMinutes(-30) } | `
ForEach-Object{$_.FullName}

 

{"originWidth":543,"originHeight":127,"style":"alignCenter","caption":"결과화면 : Get-ChildItem -Path \"경로\" -Filter \"파일명 조건\" -Recurse

 

#PowerShell 검색어 #PowerShell 파일 필터링 #PowerShell 마지막 수정 시간 확인 #PowerShell 파일 확장자 필터링 #PowerShell 파일 속성 가져오기 #PowerShell 파일 목록 가져오기 #PowerShell 파일 작업 #PowerShell 파일 처리 #PowerShell 파일 조건부 선택 #PowerShell 파일 필터링 예제 #PowerShell 파일 수정 시간 비교 #PowerShell 파일 경로 지정 #PowerShell 파일 확장자 확인 #PowerShell 파일 목록 정렬 #PowerShell 파일 작업 예제 #PowerShell Get-ChildItem 예제 #PowerShell Get-ChildItem 필터링 #PowerShell Get-ChildItem 폴더만 가져오기 #PowerShell Get-ChildItem 파일만 가져오기 #PowerShell Get-ChildItem 하위 폴더 포함 #PowerShell Get-ChildItem 특정 확장자만 가져오기 #PowerShell Get-ChildItem 파일 속성 가져오기 #PowerShell Get-ChildItem 특정 날짜 이후 가져오기 #PowerShell Get-ChildItem 특정 날짜 이전 가져오기 #PowerShell Get-ChildItem 최근 수정된 파일 가져오기 #PowerShell et-ChildItem 최근 생성된 파일 가져오기 #PowerShell Get-ChildItem 특정 시간 범위 내 파일 가져오기 #PowerShell Get-ChildItem 특정 시간 이후 수정된 파일 가져오기 #PowerShell Get-ChildItem 특정 시간 이전 생성된 파일 가져오기 #PowerShell Get-ChildItem 특정 시간 범위 내 폴더 가져오기 #PowerShell Get-ChildItem 특정 시간 이후 생성된 폴더 가져오기 #PowerShell Get-ChildItem 특정 시간 이전 수정된 폴더 가져오기

PowerShell Get-ChildItem + Where-Object + ForEach-Object 파일

Powershell_Get_ChildItem.txt
0.00MB

300x250