Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Dec 14, 2017 4:02 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Choose Location Dialogue
PostPosted: Sun Feb 24, 2013 8:33 am 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
Hi,
Is it possible for someone to tell me how to change the following line of code, in order for the user to be presented with a CHOOSE SAVE LOCATION dialogue (instead of saving to SpecialFolder.DeskTop.Child).
I need the name of the copied folder to stay the same as in the code below.

DestFolder = SpecialFolder.DeskTop.Child(SourceFolder.Name + " Backup " + "(" + str(d.day) + "." + str(d.month) + "." + str(d.year) +")")


Thank you all in advance.

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Sun Feb 24, 2013 10:24 am 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
From the LR:

Dim f As FolderItem = SelectFolder
If f <> Nil Then
DestFolder = f.Child(SourceFolder.Name + " Backup " + "(" + str(d.day) + "." + str(d.month) + "." + str(d.year) +")")(SourceFolder.Name + " Backup " + "(" + str(d.day) + "." + str(d.month) + "." + str(d.year) +")")
End if

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Sun Feb 24, 2013 12:05 pm 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
Thanks.

I am trying to create BUTTON code, which when clicked, will back-up the folder containing my .exe and the accompanying folders / files, into a directory chosen by the user.

I am almost there but not quite - therefore, would someone be kind enough to correct my code below.
I am now at the point of smashing my head against a wall :(


dim SourceFolder as FolderItem
dim DestFolder as FolderItem
dim d as new date

SourceFolder = app.ExecutableFile.Parent

Dim f As FolderItem = SelectFolder
If f <> Nil Then
DestFolder = f.Child(SourceFolder.Name + " Backup " + "(" + str(d.day) + "." + str(d.month) + "." + str(d.year) +")")
End if

if DestFolder.Exists then DestFolder.Delete

dim i, count as integer

if source.directory then
for i = 1 to source.count
count = count + CountFiles(source.item(i))
next
else
count = 1
end
return count


Dim i2 as Integer

if source.directory then // it's a folder
if destination.exists then
if not destination.directory then return // bail out
else
destination.CreateAsFolder
end if
for i2 = 1 to source.count
CopyFileOrFolder(source.item(i), destination.child(source.item(i).name))
next
else
source.CopyFileTo(destination)
FileCount = FileCount + 1
end if



FileCount = 0
FileTotal = CountFiles(SourceFolder)
CopyFileOrFolder(SourceFolder, DestFolder)


Thanks in advance.

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Sun Feb 24, 2013 1:19 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
Quote:
if source.directory then
for i = 1 to source.count
count = count + CountFiles(source.item(i))
next
else
count = 1
end
return count


I don't know what you are trying to accomplish with this function. Since you aren't checking source.item(i).directory, what you are getting you can just get with "return source.count"

Quote:
if source.directory then // it's a folder
if destination.exists then
if not destination.directory then return // bail out
else
destination.CreateAsFolder
end if


I can't tell what this does, since destination is not dimmed from any posted code. You dimmed DestFolder but haven't used it.

Quote:
Dim i2 as Integer
for i2 = 1 to source.count


A handier (better) way, since i2 is only used in this loop, is
For i2 As integer = 1 to source.count


Quote:
CopyFileOrFolder(source.item(i), destination.child(source.item(i).name))

You will need to determine is source.item(i) is a directory and then iterate through that directory to copy each of its files as well.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Sun Feb 24, 2013 1:40 pm 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
I tried to combine a couple of my snippets, and obviously messed it up completely :(

Am I right in presuming that the code below is at least right in order to allow the user to select where the files will be backed up to:

dim SourceFolder as FolderItem
dim DestFolder as FolderItem
dim d as new date

SourceFolder = app.ExecutableFile.Parent

Dim f As FolderItem = SelectFolder
If f <> Nil Then
DestFolder = f.Child(SourceFolder.Name + " Backup " + "(" + str(d.day) + "." + str(d.month) + "." + str(d.year) +")")
End if

if DestFolder.Exists then DestFolder.Delete


If I am right so far - can someone advise me what my next step should be.

Thanks.

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Sun Feb 24, 2013 3:41 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
That looks correct. Put it into a test project to confirm.
Now iterate through your source folder and copy files one at a time.
If item(i).Directory, then you will need a routine to create that folder at the destination and copy the source files to it.
This can get quite complex depending on how many levels down the directories may go.
Create some code based upon what I gave you before and let's see where you get.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Sun Feb 24, 2013 4:13 pm 
Offline

Joined: Fri Dec 01, 2006 3:09 pm
Posts: 650
Location: Tennessee, USA
Also keep in mind the fact that you cannot delete a directory unless that directory is empty, contains no files or other directories within it. The FolderItem.Delete page in the Language Reference has an example of a good way to write code to delete a directory (folder). It will delete all files and directories within it.

You may also want to add the date to the end of the file name in year, month, day order. Doing it the way you are doing it the files will end up in no meaningful seguence. Going year month day they will appear in a nice chronological order. But, that is simply the way I prefer to do it so go whichever way suits you.

One last thing, as your code is written you use SelectFolder to have get the directory for where the backups are to be located. You test if f <> nil in case Cancel is clicked in the SelectFolder dialog. If it is not nil you then compute the DestFolder folderitem. After that if clause you then continue on. If f were nil at the point of the if test, it would still be nil as you continue in to the rest of your computations which would lead to a lot of grief. If f were nil then you should more than likely exit the current method.


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Sun Feb 24, 2013 5:10 pm 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
I really appreciate everyoe's help, but I am in way over my head on this one :(
Although the next step has been pointed out, I have absolutely no idea where to start.

It looks as though I will have to pay someone for the complete snippet, and then casually break the code down, study it, and learn how each part of the code works.

SO

If anyone would like to earn some extra dollars, and also help me to learn how to do this - please let me know how much.

I know when I am beaten and know my own capabilities - and there is no way on earth that I can complete this code with my current knowledge.

Hope someone can help
Thanks.

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Sun Feb 24, 2013 9:51 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
Here you go:
http://www.classonesoftware.com/Beta/CopyTry.zip

I think this does mostly what you want. Make the changes you need for your situation.
The bulk of this code is available in the LR under folderitem.CopyFileTo

Turns out that deleting the dest. file each time is not necessary. Just doing
DestFolder.createAsFolder overwrites the folder that might be there.

Hope this helps.

*Note: Tested ONLY on Mac.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Mon Feb 25, 2013 1:07 am 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
Thank you sooooooooo much classone - it worked perfectly on Windows 7!

I am sure that you will now start laughing at me, but I thought I would do the simple task of converting the "SelectFolder()" snippet below, into a "SelectFolderDialog".

Dim srcFolder As FolderItem = GetFolderItem("")
Dim destFolder As FolderItem
dim d As new date

destFolder = SelectFolder()

if destFolder <> Nil Then
destFolder = destFolder.Child(" Backup " + "(" + str(d.day) + "-" + str(d.month) + "-" + str(d.year) + "@" + str(d.hour) + "." + str(d.minute) + "." + str(d.second) +"hrs" +")")
destFolder.CreateAsFolder

for i As Integer = 1 to srcFolder.Count
CopyFileOrFolder(srcFolder.Item(i), destFolder)
Next

end if


WRONG !

I tried this:

Dim srcFolder As FolderItem = GetFolderItem("")
Dim destFolder As FolderItem
dim d As new date

destFolder As New SelectFolderDialog

if destFolder <> Nil Then
destFolder = destFolder.Child(" Backup " + "(" + str(d.day) + "-" + str(d.month) + "-" + str(d.year) + "@" + str(d.hour) + "." + str(d.minute) + "." + str(d.second) +"hrs" +")")
destFolder.CreateAsFolder

for i As Integer = 1 to srcFolder.Count
CopyFileOrFolder(srcFolder.Item(i), destFolder)
Next

end if


WRONG!

Then I tried this:

Dim srcFolder As FolderItem = GetFolderItem("")
Dim destFolder As New SelectFolderDialog
dim d As new date

if destFolder <> Nil Then
destFolder = destFolder.Child(" Backup " + "(" + str(d.day) + "-" + str(d.month) + "-" + str(d.year) + "@" + str(d.hour) + "." + str(d.minute) + "." + str(d.second) +"hrs" +")")
destFolder.CreateAsFolder

for i As Integer = 1 to srcFolder.Count
CopyFileOrFolder(srcFolder.Item(i), destFolder)
Next

end if


WRONG!
Arrrrrrrrrrrrrrggggggggggggggggghhhhhhhhhhhhhhhhhhhhhh :( :( :( :( :(

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Mon Feb 25, 2013 7:26 am 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
Dim srcFolder As FolderItem = GetFolderItem("")
Dim destFolder As FolderItem
dim d As new date
Dim dlg As New SelectFolderDialog
dlg.ActionButtonCaption = "Pick Me"
dlg.Title = "Title Property"
dlg.PromptText = "Prompt Text"
dlg.InitialDirectory = SpecialFolder.Documents
destFolder = dlg.ShowModal

if destFolder <> Nil Then
destFolder = destFolder.Child("MyContents_"+str(d.year)+str(d.Month)+str(d.day))
destFolder.CreateAsFolder

for i As Integer = 1 to srcFolder.Count
CopyFileOrFolder(srcFolder.Item(i), destFolder)
Next

end if


All I did was copy code snippets from the Language Ref. and paste here. Please have a look at the LR and try a few of its examples. It can be very helpful.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Mon Feb 25, 2013 7:46 am 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
Once again, THANK YOU !

I can understand seperate snippets, but I always have trouble combining them.
Then I get so muddled up that it all becomes a blur :)

Anyway, THANK YOU!

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Mon Feb 25, 2013 7:16 pm 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
All working perfect now :)

Still only allows me to back-up ONCE though ??
I have no idea why previous backups are not overwritten - even though all backups have the same name??

All ideas welcome :)

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Mon Feb 25, 2013 10:05 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
Well, the code I published overwrote the previous using Mac 10.8 when I tried it. I did not try Win so the behavior may well be different there.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Choose Location Dialogue
PostPosted: Mon Feb 25, 2013 10:20 pm 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
Must be.

Never mind - I am sure a workaround will eventually be figured out.
Until then I can live with only 1 back-up per application startup.

Thank you for all your help.

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group