Jump to content
Sign in to follow this  

FileListToArray help

Recommended Posts


First let me explain what this is supposed to do...

This is supposed to get a list of all folders inside the "Images" folder that start with "12_" Which it does. Then it's supposed to zip up each individual folder that is inside the folder that starts with "12_" which it does.

However, I have two problems...

1. If one of the 12_ folders is empty the program will generate a msgbox saying the name of the folder it came across that was empty, and then stop.

Would it be possible to exclude folders that start with 12_ but are empty? If so how? If not, how could I make it skip the empty 12_ABCDEF folder and continue to the next one that might not be empty?

2. While everything zips the way I want it to... I don't like the fact that the archive is structured like ... 12_ABCDEF/SUBDIRECTORY1/FILESANDFOLDERS I want the archive to only be SUBDIRECTORY1/FILESANDFOLDERS Does that make sense?

Thank you!

#Include <File.au3>
#Include <Array.au3>
#include <7Zip.au3>

;Get list of folders that contain 12_ and add to array
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")

;Delete the count of how many are in array

;Get highest number of row in array
$MaxIndex = _ArrayMaxIndex($FileList)

;Get list of folders inside the $FileList array
$i = 0

    $SubList = _FileListToArray("C:\Imaging\Images\"&$FileList[$i])
    If @error Then MsgBox(0,"",$FileList[$i] & " " & "is empty")
    ;Delete the count of how many are in array

;Get highest number of row in array
$MaxSubIndex = _ArrayMaxIndex($SubList)

;Zip up all the folders that are in the FileList subdirectories.
$b = 0
$ArcFile = "\\UAC20\Home\jason\My Documents\programs\"&$FileList[$i]&"\"&$SubList[$b]&".zip"
If @error Then Exit

$FileName = "C:\Imaging\Images\"&$SubList[$b]
If @error Then Exit

$retResult = _7ZipAdd(0, $ArcFile, $FileName)

$b = $b + 1
Until $b = $MaxSubIndex+1

$i = $i + 1
Until $i = $MaxIndex+1

Share this post

Link to post
Share on other sites

You can use DirGetSize() to see if the directory is empty of files before passing it's path name to _7ZipAdd() function.

Organizing the directory structure to your likes require a recursive function to list all of the directory sub-folders/files and moving them to the top level directory, deleting the reminder empty folders and then passing it to the _7ZipAdd() function. Search the Example Scripts forum for the recursive file listing function, there are quite a lot of them.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.