New topic: 

Making sure input file and output file are not the same

<http://forums.realsoftware.com/viewtopic.php?t=30593>

       Page 1 of 1
   [ 9 posts ]                 Previous topic | Next topic         Author  
Message       B0B           Post subject: Making sure input file and output 
file are not the samePosted: Wed Oct 21, 2009 8:57 pm                        
Joined: Sun Mar 05, 2006 5:29 am
Posts: 68              I have an application that processes text files. It 
opens an input file, processes text and sends it to an output file.

I need to check for the situation where the user inadvertently selects the 
output path and file name to be exactly the same as the input file. The usual 
save file dialog is fine for warning the user that the file exists, and I don't 
want to prevent him from overwriting another file as long as it's not the input 
file. Is there a quick way to tell if the folderitems returned by 
GetOpenFolderItem and GetSaveFolderItem refer to the same file?     
_________________
MacBook Pro (Intel) OSX 10.5; RealBasic 2009 r1  
                            Top               timhare           Post subject: 
Re: Making sure input file and output file are not the samePosted: Wed Oct 21, 
2009 9:12 pm                        
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6603
Location: Portland, OR  USA              Test their AbsolutePath's.
Code:dim fileIn, fileOut as FolderItem
fileIn = GetOpenFolderItem(...)
fileOut = GetSaveFolderItem(...)
if fileIn.AbsolutePath = fileOut.AbsolutePath then
  msgBox "Please choose another file for output"
end


Tim   
                            Top               B0B           Post subject: Re: 
Making sure input file and output file are not the samePosted: Wed Oct 21, 2009 
9:18 pm                        
Joined: Sun Mar 05, 2006 5:29 am
Posts: 68              Okay thanks. I wasn't sure that absolute path would 
return identical strings for both folderitems.     
_________________
MacBook Pro (Intel) OSX 10.5; RealBasic 2009 r1  
                            Top               timhare           Post subject: 
Re: Making sure input file and output file are not the samePosted: Wed Oct 21, 
2009 9:20 pm                        
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6603
Location: Portland, OR  USA              AbsolutePath can be problematic on 
Mac, but if you just aquired them both, then it will be identical.  The 
problems arise when you try to use a "stale" absolute path.  You could 
GetSaveInfo for this, but it would be overkill.   
                            Top               Phil M           Post subject: 
Re: Making sure input file and output file are not the samePosted: Wed Oct 21, 
2009 10:22 pm                        
Joined: Fri Sep 30, 2005 12:18 pm
Posts: 185              Do you want to check for aliased files as well?  Only 
comparing AbsolutePath will say they are unique (because they technically are), 
but they still point to the same physical file.   
                            Top               B0B           Post subject: Re: 
Making sure input file and output file are not the samePosted: Wed Oct 21, 2009 
10:28 pm                        
Joined: Sun Mar 05, 2006 5:29 am
Posts: 68              Interesting point. Is there an easy way of resolving 
aliases into the absolute path of the actual file?     
_________________
MacBook Pro (Intel) OSX 10.5; RealBasic 2009 r1  
                            Top               Pariahware           Post 
subject: Re: Making sure input file and output file are not the samePosted: Wed 
Oct 21, 2009 10:44 pm                               
Joined: Fri Sep 30, 2005 10:00 am
Posts: 962
Location: Raleigh, NC              Why not read the contents of both files in 
via a binary stream and compare the two?     
_________________
Christian
Pariahware, Inc.
Mac, Windows, Linux, & iPhone Consulting
[email protected]
http://www.pariahware.com/

The Association of REALbasic Professionals
http://www.arbp.org/
--
God loved you so much that He gave His only son Jesus.  What have you done with 
God's gift?  
                            Top               timhare           Post subject: 
Re: Making sure input file and output file are not the samePosted: Wed Oct 21, 
2009 11:03 pm                        
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6603
Location: Portland, OR  USA              GetOpenFolderItem and 
GetSaveFolderItem resolve aliases.   
                            Top               B0B           Post subject: Re: 
Making sure input file and output file are not the samePosted: Wed Oct 21, 2009 
11:05 pm                        
Joined: Sun Mar 05, 2006 5:29 am
Posts: 68              Hi Tim, Thanks. Comparing absolute paths seems to work 
well.

Pariahware wrote:Why not read the contents of both files in via a binary stream 
and compare the two?
There's a good chance that the there could be duplicate files with the exact 
same information. So that wouldn't necessarily solve the problem; not to 
mention that it's far more work than I want to do.     
_________________
MacBook Pro (Intel) OSX 10.5; RealBasic 2009 r1  
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 9 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to