Skip to content
Tutorial emka
Menu
  • Home
  • Debian Linux
  • Ubuntu Linux
  • Red Hat Linux
Menu

Tutorial Cara Memeriksa Keberadaan File dan Folder Menggunakan PowerShell

Posted on November 13, 2024

Mengelola file dan folder merupakan bagian penting dalam banyak tugas otomatisasi, dan PowerShell merupakan alat yang ampuh untuk melakukannya. PowerShell memungkinkan Anda melakukan berbagai tugas, termasuk memeriksa keberadaan file dan folder di sistem Anda. Dengan demikian, Anda dapat dengan cepat memeriksa keberadaan beberapa file dan folder sekaligus.

Test-Path$true$false

Memeriksa Keberadaan File

Untuk memeriksa apakah sebuah file ada atau tidak, Anda perlu menulis kode pernyataan dan sederhana seperti ini:

      if (Test-Path "F:wp-config.php") {
Write-Output "File tersebut ada."
} else {
Write-Output "File tersebut tidak ada."
}
    
Use code with caution.Powershell

Memeriksa Keberadaan Folder

Demikian pula, Anda harus mengubah jalur ke lokasi folder untuk memeriksa apakah folder tersebut ada.

      if (Test-Path "F:Backup") {
Write-Output "Folder tersebut ada."
} else {
Write-Output "Folder tersebut tidak ada."
}
    
Use code with caution.Powershell

      $paths = @(
"C:Usersfile.webp",
"C:UsersReport.docx",
"C:UsersProfilePic.png",
"C:Usersfavorites",
"C:UsersVacation"
)

$results = @()

foreach ($path in $paths) {
if (Test-Path $path) {
$results += "$path ada."
} else {
$results += "$path tidak ada."
}
}

$results | ForEach-Object { Write-Output $_ }
    
Use code with caution.Powershell

Menggunakan dengan Wildcard

Anda juga dapat menggunakan untuk memeriksa apakah file tertentu ada di direktori atau tidak menggunakan Wildcard.

      if (-Not (Test-Path "C:pathtonewfolder")) {
New-Item -Path "C:pathtonewfolder" -ItemType Directory
Write-Output "Folder dibuat."
} else {
Write-Output "Folder sudah ada."
}
    
Use code with caution.Powershell

      if (-Not (Test-Path "C:pathtonewfolder")) {
New-Item -Path "C:pathtonewfolder" -ItemType Directory
Write-Output "Folder dibuat."
} else {
Write-Output "Folder sudah ada."
}
    
Use code with caution.Powershell

Bisakah Saya Memeriksa File atau Folder Tersembunyi Menggunakan PowerShell?

Anda dapat memeriksa file dan folder tersembunyi menggunakan cmdlet dan parameter untuk menyertakan item tersembunyi. Anda dapat menyaring hasilnya menggunakan untuk memeriksa item dengan atribut “Hidden”.Test-PathTest-Path

Recent Posts

  • How to build a high-performance private photo cloud with Immich and TrueNAS SCALE
  • How to Build an Endgame Local AI Agent Setup Using an 8-Node NVIDIA Cluster with 1TB Memory
  • How to Master Windows Event Logs to Level Up Your Cybersecurity Investigations and SOC Career
  • How to Build Ultra-Resilient Databases with Amazon Aurora Global Database and RDS Proxy for Maximum Uptime and Performance
  • How to Build Real-Time Personalization Systems Using AWS Agentic AI to Make Every User Feel Special
  • How to Transform Your Windows 11 Interface into a Sleek and Modern Aesthetic Masterpiece
  • How to Understand Google’s New TPU 8 Series for Massive AI Training and Inference
  • How to Level Up Your PC Gaming Experience with the New Valve Steam Controller and Its Advanced Features
  • Is it Time to Replace Nano? Discover Fresh, the Terminal Text Editor You Actually Want to Use
  • How to Design a Services Like Google Ads
  • How to Fix 0x800ccc0b Outlook Error: Step-by-Step Guide for Beginners
  • How to Fix NVIDIA App Error on Windows 11: Simple Guide
  • How to Fix Excel Formula Errors: Quick Fixes for #NAME
  • How to Clear Copilot Memory in Windows 11 Step by Step
  • How to Show Battery Percentage on Windows 11
  • How to Fix VMSp Service Failed to Start on Windows 10/11
  • How to Fix Taskbar Icon Order in Windows 11/10
  • How to Disable Personalized Ads in Copilot on Windows 11
  • What is the Microsoft Teams Error “We Couldn’t Connect the Call” Error?
  • Why Does the VirtualBox System Service Terminate Unexpectedly? Here is the Full Definition
  • Why is Your Laptop Touchpad Overheating? Here are the Causes and Fixes
  • How to Disable All AI Features in Chrome Using Windows 11 Registry
  • How to Avoid Problematic Windows Updates: A Guide to System Stability
  • What is Microsoft Visual C++ Redistributable and How to Fix Common Errors?
  • What is the 99% Deletion Bug? Understanding and Fixing Windows 11 File Errors
  • Inilah Penemuan Fosil Hadrosaurus yang Ungkap Bahwa Penyakit Langka Manusia Sudah Ada Sejak Zaman Prasejarah
  • Inilah Penemuan Terbaru yang Mengungkap Bahwa Sunburn Ternyata Disebabkan Oleh Kerusakan RNA
  • Inilah Alasan Kenapa Manusia Lebih Sering Hamil Satu Bayi daripada Kembar Menurut Penelitian Terbaru
  • Inilah Syarat dan Cara Pendaftaran IMEI Internasional Mulai Mei 2026
  • Bocoran Spek Samsung Galaxy S27 Ultra Nih, Kamera 3X Hilang + Teknologi AI
  • How to Clone Your Voice for Free and Create Unlimited AI Audio
  • How to Deploy Your Google AI Studio Web App Using Hostinger
  • How to Create Viral Motivational YouTube Videos Using Only Free AI
  • How to Create High-End Cinematic Ads and Viral Content with Seedance 2.0
  • How OpenAI is Taking the Lead Again with GPT 5.5 and Codex
  • Apa itu Spear-Phishing via npm? Ini Pengertian dan Cara Kerjanya yang Makin Licin
  • Apa Itu Predator Spyware? Ini Pengertian dan Kontroversi Penghapusan Sanksinya
  • Mengenal Apa itu TONESHELL: Backdoor Berbahaya dari Kelompok Mustang Panda
  • Siapa itu Kelompok Hacker Silver Fox?
  • Apa itu CVE-2025-52691 SmarterMail? Celah Keamanan Paling Berbahaya Tahun 2025
©2026 Tutorial emka | Design: Newspaperly WordPress Theme