How to Add a Top Level Empty Directory to a Zip File on Windows

Abstract: Resolve Windows zip utility ignoring empty directories by using a placeholder file to preserve directory structure in archives.

Created: 2026-08-23 by

You can add a top-level empty directory to a zip file on Windows by creating a placeholder file inside that folder, compressing the folder, and then using PowerShell or the command line to remove the placeholder while preserving the directory structure. This method ensures the empty folder exists in the final archive, which is essential for maintaining specific project layouts or compatibility with certain deployment tools.

Understanding Zip File Structure Limitations

Standard compression utilities like the built-in Windows Explorer often ignore empty folders when creating archives. When you right-click a folder and select "Send to > Compressed Folder," Windows only includes files that have content. If a directory contains no files, it is excluded from the resulting .zip package. This behavior can cause issues when extracting archives on other systems or when specific software expects a particular directory hierarchy to exist immediately upon extraction. To work around this limitation, you must trick the compression utility into including the folder by placing at least one item inside it. Once compressed, you can remove that item without collapsing the folder itself. This approach preserves the empty state of the directory within the archive structure. Understanding this quirk is crucial for developers and system administrators who need precise control over their deployment packages.

Creating the Placeholder File

The first step involves preparing your directory structure. Navigate to the location where you want to create the new empty directory. Right-click in the desired parent folder and select New > Folder. Name this folder according to your requirements, such as empty_dir. Inside this newly created folder, you need to create a dummy file. This file serves as the anchor that forces the zip utility to recognize and include the directory. You can create a simple text file named .placeholder or keep.txt. Using a dot prefix is common practice because many operating systems and version control systems treat files starting with a dot as hidden or configuration files, making them less likely to interfere with your actual data. Right-click inside the folder, select New > Text Document, and rename it to .placeholder. Press Enter to confirm the name change. Ensure that the file extension is not accidentally removed by Windows. The file can be completely empty; its content does not matter, only its existence within the directory tree.

Compressing the Directory

With the placeholder file in place, you can now create the zip archive. Return to the parent folder containing your new directory. Right-click on the parent folder and select Send to > Compressed ZIP file. Windows will generate a new .zip file containing both the placeholder file and the directory structure. Alternatively, you can use the command line for more precision. Open Command Prompt or PowerShell and navigate to the parent directory. Use the following command to create the archive:
Compress-Archive -Path .\empty_dir -DestinationPath archive.zip
This command explicitly targets the folder, ensuring it is included in the output. The resulting archive will contain the directory and the placeholder file. At this stage, the empty directory effectively exists within the zip file, albeit occupied by the dummy file.

Removing the Placeholder via PowerShell

To finalize the process, you must remove the placeholder file from the zip archive without deleting the directory. While some third-party tools offer graphical interfaces for this, PowerShell provides a robust native solution. You can use the System.IO.Compression.ZipFile class to manipulate the archive contents directly. Open PowerShell and run the following script to open the zip file, identify the placeholder entry, and delete it:
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zip = [System.IO.Compression.ZipFile]::Open("archive.zip", "Update")
$entry = $zip.Entries | Where-Object { $_.FullName -eq "empty_dir/.placeholder" }
if ($entry) { $entry.Delete() }
$zip.Dispose()
This script opens the existing zip file in update mode, locates the specific entry corresponding to the placeholder file, and deletes it. Because the directory entry remains intact in the archive's metadata, the folder persists as an empty container. The $zip.Dispose() command ensures all changes are saved and the file handle is closed properly.

Verifying the Result

After running the script, verify that the archive contains the empty directory. You can do this by opening the .zip file in Windows Explorer or using PowerShell to list the contents. Check that the directory structure is preserved and that the placeholder file is gone. This verification step confirms that the directory is truly empty within the archive. If you encounter errors, ensure that the path to the placeholder file matches exactly what was compressed. Case sensitivity can sometimes cause issues depending on the platform extracting the archive. Additionally, always backup your original archive before performing destructive operations like deletion within the zip structure. For users managing complex file systems, understanding how to locate critical components is also helpful. You might find it useful to review Where are my system files located in Windows? to better understand the underlying file hierarchy.

Frequently Asked Questions

Why doesn't Windows include empty folders when zipping?

Windows Explorer is designed to optimize storage by excluding directories that contain no files. This default behavior reduces the size of the archive but can break workflows that rely on specific folder structures. To include empty folders, you must manually add a placeholder file to force inclusion during the compression phase.

Can I use 7-Zip to add empty directories?

Yes, 7-Zip handles empty directories differently than Windows Explorer. When adding files to an archive, 7-Zip typically preserves the entire directory tree, including empty folders, even if they contain no files. This makes it a preferred tool for developers who need precise control over archive structure without needing placeholder hacks.

What happens if I delete the wrong file from the zip?

Deleting the wrong file may leave the directory intact but could remove necessary data if you misidentify the placeholder. Always double-check the full path of the entry before executing the delete command. It is safer to keep a backup of the original zip file until you have verified the final result.

Does this method work for nested empty directories?

Yes, you can apply the same logic to nested directories. Create placeholder files in each empty subdirectory you wish to preserve, compress the entire structure, and then use a script to iterate through and remove all placeholders. This ensures that deep folder hierarchies remain intact in the final archive.

Are there any risks associated with modifying zip files programmatically?

Modifying zip files directly carries a risk of corruption if the process is interrupted or if permissions are incorrect. Always ensure you have write access to the target file and avoid editing large archives during peak system load. Using established libraries like those in PowerShell reduces the risk compared to manual binary editing.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More