I'm trying to zip multiple folders with several layers of subfolders that contain .jpg and .png files. My goal is to create a zip file for each folder, using that folder's name for the zip file. For example, if I have a folder structure like this: 'Photos > Family > Brother', I want to create a file named 'brother.zip' that contains everything from the Brother folder. However, I have a PowerShell script that's supposed to do this, but it's not functioning as expected. I'd like some help troubleshooting it and getting the desired outcome.
4 Answers
Just to confirm, your plan is to create zip files alongside your images with the name of the parent folder, right? For example, if your images are in 'c:famevent', you'll have an 'event.zip' there containing all images from that directory? If so, you're on the right track! Just adjust where you're placing the zip files.
You might complicate things less by first gathering a list of all directories with image files. You could use `-File -Recurse` to collect these paths, then iterate through that list to create your zips. Just remember that directory names can conflict if you have similar folder names in different paths! Ensure to check the full path so there's no confusion.
When zipping your files, it’s often helpful to first run a discovery process in your script to gather all file and folder details. Look at the files, report back what you find, then perform your compression based on that data. This method helps to ensure you know exactly what you’re dealing with before making any changes.
It looks like the issue might be with how you're building the path for your zip files. Using `Join-Path $RootDirectory ($FolderName + ".zip")` could lead to problems if the structure is nested and you just need the current folder name. Instead, try creating the zip file in the same directory as the images like this: `$ZipFilePath = Join-Path $FolderPath ($FolderName + ".zip")` to ensure it's created right there in each folder. Also, make sure your script isn't accidentally creating duplicates by checking if there’s already a zip file before creating a new one.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String