Install files if directory empty - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

FergusMurray
Posts: 150
Joined: Thu Sep 30, 2010 10:44 am

Install files if directory empty

Would like to add this functionality to my install

If an installed directory is empty then deliver the "example" files, if the directory is not empty do not deliver anything in that directory

So far my approach has been :
1. create a separate feature for the folder
2. create a property that will hold whether it should copy the files or not
3. make the feature only install if the property is set to 0
4. use some .vbs to test whether the folder is empty and set the variable

is this the best approach to achive this, or is there a way i can avoid the vbs route?

Cheers,
Fergus.
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Install files if directory empty

Hello Fergus,

Here is a thread that can help you with the condition.
Our predefined search from the Search Page can help you verify if a folder exists on the target machine, not if its empty. Still, if you don't know any of the files that would reside in that folder to add a predefined search for any of them in the Search Page, like you said, you will need to verify that the folder is empty from within your own custom action.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
FergusMurray
Posts: 150
Joined: Thu Sep 30, 2010 10:44 am

Re: Install files if directory empty

Went the VBS route, attached my vbs in case its any use to anyone else :

Code: Select all

Function WriteToLog(TextToWrite)
  Const MsgType = &H04000000
  Set rec = Installer.CreateRecord(1)
  rec.StringData(1) = TextToWrite
  
  Session.Message MsgType, rec
'Msgbox TextToWrite
WriteToLog = 0
End Function

Function CheckForScreens()
Dim fso, msg, objFSO, objFolder,colFiles,counted,temp, Installdir
Installdir=Session.Property("APPDIR")&"Settings\Screens"
Set fso = CreateObject("Scripting.FileSystemObject")
counted=0
WriteToLog("CheckForScreens: Looking for "&Installdir)
If (fso.FolderExists(Installdir)) Then
	WriteToLog("CheckForScreens: Found existing screens folder, checking contents..")
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFolder = objFSO.GetFolder(Installdir)
	Set colFiles = objFolder.Files
	For Each objFile in colFiles
		WriteToLog("CheckForScreens: found "&objFile.Name)
		' only count XML files, as these are the ones we're interested in
		If UCase(Right(objFile.Name,3))="XML" then
			counted=counted+1
		End if
	Next
	WriteToLog("CheckForScreens: found "&Cstr(counted)&" XML screens")
	if counted > 0 then
		WriteToLog("CheckForScreens: returned=0")
		Session.Property("APERTA_DEFAULTSCREENSEMPTY")="0"
	else
		WriteToLog("CheckForScreens: returned=1")
		Session.Property("APERTA_DEFAULTSCREENSEMPTY")="1"
	end if
Else
	WriteToLog("CheckForScreens: returned=1")
	Session.Property("APERTA_DEFAULTSCREENSEMPTY")="1"
End If
End Function
Last edited by FergusMurray on Tue May 17, 2011 3:30 pm, edited 1 time in total.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Install files if directory empty

Hi Fergus,

Thank you for posting your code, I am sure other users will find useful.
(although the forum killed the indents)
For this you could try using the "Code" tag when creating/editing the post, this should keep the formatting of the code.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”