empty directory

Nov 29, 2010 at 2:19 PM

Hi,

I use this script. It's great. But i've one question. If i've empty direcory in my backup location it is ignored and doesnt archiwe in creating zip file.Why? How i can archiwe empty directory?

Please help me because i'm sitting on it a long time and i give up.

Coordinator
Nov 29, 2010 at 6:39 PM

Hi nemook,

thank you for your feedback.

Unfortunately my script only looks for files, not directories. (Look main page at the section "What 7zbackup.ps1 IS NOT and what it can't do")
There could be a way to include empty directories in 7zip archiving but this involves the adoption of wildcard selectors, and this is exactly what caused problems in archiving from multiple different paths (which is the reason which lead me to the writing of the script).

I am sorry this is causing you problems but, at present, I cannot see any valuable solution unless you drop a dummy file into your empty dirs before the backup begins.

Regards.

Nov 30, 2010 at 8:25 AM

Hi Alan,

Thanks for your quick replay.

I must think about it. If I've some proposition to resolve this problem i'm writing here.

Regards,

Nov 30, 2010 at 3:08 PM

Hi Alan,

 

Could you tell me how i can print result my script on console window and save it to txt file in the same time?

I will be glad for your help.

 

Regards

Coordinator
Nov 30, 2010 at 3:18 PM

Hi nemook,

if you look at my script that is quite simple.

I have created a Function named "Trace" like this:

Function Trace ($message, $outfile1, $outfile2) {
	Write-Host $message
	if (($outfile1)) { $message | out-file $outfile1 -encoding ASCII -append }
	if (($outfile2)) { $message | out-file $outfile2 -encoding ASCII -append }
}

Then when you have to send data on screen only you have to call this function passing the message only:

Trace "Some very useful message"

Else, if you need to write the message both on screen and file simply call this way:

Trace "Some very useful message" "C:\mylog.txt"
Bye

 

Jun 9, 2011 at 9:55 AM
nemook wrote:

Hi,

I use this script. It's great. But i've one question. If i've empty direcory in my backup location it is ignored and doesnt archiwe in creating zip file.Why? How i can archiwe empty directory?

Please help me because i'm sitting on it a long time and i give up.

Hi,

I had the same problem when needed to backup entire SVN root, which contained a lot of empty directories. I was not sure, how SVN will behave, if these directories will not exist after restore. So I decided to apply minor modification to the original script (v 1.7.3):

#include empty folders to the backup
if ((Get-ChildItem $folderPath).Count -eq 0) {
    if($thisRelativePath -ne "\") {
        "$thisRelativePath\" + $_.Name | Out-File $BkCatalogInclude -encoding UTF8 -append
    }
    return
}
else {
    # Read trough items in directory
    ...

This code is placed in the ProcessFolder function, before the child items loop is starting (line 976 in the original script).

It works. However, it might not work properly in some scenarious. For example, if you specify to exclude some empty folders in the selection file.

Coordinator
Jun 9, 2011 at 11:43 AM

Hi emakovich,

thank you for your contribution ! I have investigated your solution and I am afraid it might not be enough to accomplish the job even if I have not tested it yet. According to 7zip documentation the only way to store empty folders labels inside an archive file is to invoke 7zip with the -r0 switch set *and* to include the name of the empty directory in the catalog list file followed by an asterisk. Therefore your code should look like this:

 

#include empty folders to the backup
if ((Get-ChildItem $folderPath).Count -eq 0) {
    if($thisRelativePath -ne "\") {
        "$thisRelativePath\" + $_.Name + "\*" | Out-File $BkCatalogInclude -encoding UTF8 -append
    }
    return
}
else {
    # Read trough items in directory
    ...

In addition you should also handle the $Bk7ZipSwitches variable to include the -r0 switch.

I will do some tests and let you know.

 

Jun 9, 2011 at 12:42 PM

Hi! Thanks for your answer.

Maybe it depends on the 7Zip version, I don`t know. Currently I`m using the latest one (9.20).