New topic: 

Working with files on disk and the Shell (how do I?)

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

         Page 1 of 1
   [ 10 posts ]                 Previous topic | Next topic          Author  
Message        RickYerex          Post subject: Working with files on disk and 
the Shell (how do I?)Posted: Wed Jan 16, 2013 12:30 pm                         
Joined: Tue Nov 29, 2011 12:50 pm
Posts: 83                I want to write a small RB application that does the 
following ...

Checks for the existance of a specific file in a specific folder.
If the file exists, process a shell command on that file.


I know how to make the shell command I want to work, but I can't figgure out 
how to code the app to check for the existance of the file first.

Any help appreciated.   
                             Top                ktekinay          Post subject: 
Re: Working with files on disk and the Shell (how do I?)Posted: Wed Jan 16, 
2013 12:41 pm                                 
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 360
Location: New York, NY                dim f as FolderItem = GetFolderItem( 
pathToFile )
if f.Exists then ...
      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top                RickYerex          Post 
subject: Re: Working with files on disk and the Shell (how do I?)Posted: Wed 
Jan 16, 2013 12:58 pm                         
Joined: Tue Nov 29, 2011 12:50 pm
Posts: 83                ktekinay wrote:dim f as FolderItem = GetFolderItem( 
pathToFile )
if f.Exists then ...


Thanks, that works but only if I specify the full file name.

Unfortunately, this file name changes from one day to the next; however, it 
does have a consistent extension.

For example, today the file name might be DailyFullBackup_full_b3_s1_v1.tib
Tomorrow it might be DailyFullBackup_full_b4_s1_v1.tib

How can I deal with that if I'm never sure what the exact file name will be?  I 
tried using just *.tib but I get a Nil Object exception error.   
                             Top                markwalsh          Post 
subject: Re: Working with files on disk and the Shell (how do I?)Posted: Wed 
Jan 16, 2013 1:07 pm                         
Joined: Wed May 20, 2009 4:43 pm
Posts: 925                RickYerex wrote:Checks for the existance of a 
specific file in a specific folder.
RickYerex wrote: Thanks, that works but only if I specify the full file name.
I'm sorry, but there's no way for us to know how your files are going to be 
named. You asked for how to check for a specific file in a specific folder, and 
that's what was provided. Otherwise, you're going to have to help us determine 
which file it is in the folder you are looking for.

Is this the only file with that specific extension in that folder?      
_________________
RB 2009r4 Windows XP  
                             Top                DaveS          Post subject: 
Re: Working with files on disk and the Shell (how do I?)Posted: Wed Jan 16, 
2013 1:09 pm                                 
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4416
Location: San Diego, CA                Get a FolderItem pointing to the FOLDER, 
and then loop thru all of its children checking each files extension      
_________________
Dave Sisemore
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                ktekinay          Post subject: 
Re: Working with files on disk and the Shell (how do I?)Posted: Wed Jan 16, 
2013 1:10 pm                                 
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 360
Location: New York, NY                You have to loop through the folder and 
find the file yourself:
dim parentFolder as FolderItem = GetFolderItem( pathToParent )
dim cnt as integer = parentFolder.Count
dim targetFile as FolderItem
for i as integer = 1 to cnt
  dim thisFile as FolderItem = parentFolder.Item( i )
  dim thisName as string = thisFile.Name
  if thisName.Right( 4 ) = ".tib" then // Assumes the extension is the only 
criteria
  targetFile = thisFile
  exit
  end if
next
if targetFile <> nil then
  ...
end if

(Written off the top of my head and not tested.)      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top                charonn0          Post subject: 
Re: Working with files on disk and the Shell (how do I?)Posted: Wed Jan 16, 
2013 1:10 pm                                 
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1068
Location: San Francisco, CA, USA                The FolderItem class doesn't 
support wildcards. To search a directory for a file use the FolderItem.Item 
method to look at each file in the directory in turn. e.g.:

Dim theParentDir As FolderItem 'The directory to search
For i As Integer = 1 To theParentDir.Count
  If theParentDir.Item(i).Name = "foo.bar" Then ' just for example
  'Found it!
  Exit For i
  End If
Next


Note that for very large directories, FolderItem.Item will be very slow.      
_________________
Boredom Software  
                             Top                RickYerex          Post 
subject: Re: Working with files on disk and the Shell (how do I?)Posted: Wed 
Jan 16, 2013 1:48 pm                         
Joined: Tue Nov 29, 2011 12:50 pm
Posts: 83                ktekinay wrote:You have to loop through the folder and 
find the file yourself:
dim parentFolder as FolderItem = GetFolderItem( pathToParent )
dim cnt as integer = parentFolder.Count
dim targetFile as FolderItem
for i as integer = 1 to cnt
  dim thisFile as FolderItem = parentFolder.Item( i )
  dim thisName as string = thisFile.Name
  if thisName.Right( 4 ) = ".tib" then // Assumes the extension is the only 
criteria
  targetFile = thisFile
  exit
  end if
next
if targetFile <> nil then
  ...
end if

(Written off the top of my head and not tested.)

That works just fine and thanks again ... exactly what I needed.   
                             Top                RickYerex          Post 
subject: Re: Working with files on disk and the Shell (how do I?)Posted: Wed 
Jan 16, 2013 1:51 pm                         
Joined: Tue Nov 29, 2011 12:50 pm
Posts: 83                markwalsh wrote:RickYerex wrote:Checks for the 
existance of a specific file in a specific folder.
RickYerex wrote: Thanks, that works but only if I specify the full file name.
I'm sorry, but there's no way for us to know how your files are going to be 
named. You asked for how to check for a specific file in a specific folder, and 
that's what was provided. Otherwise, you're going to have to help us determine 
which file it is in the folder you are looking for.

Is this the only file with that specific extension in that folder?

my BAD ... so sorry ... I will try and be more specific (pun intended) in 
future. Just ASSumed wildcards would work. It is a specific file (per se`) and 
yes, there is only one " .tib " file.   
                             Top                markwalsh          Post 
subject: Re: Working with files on disk and the Shell (how do I?)Posted: Wed 
Jan 16, 2013 2:03 pm                         
Joined: Wed May 20, 2009 4:43 pm
Posts: 925                RickYerex wrote:markwalsh wrote:RickYerex 
wrote:Checks for the existance of a specific file in a specific folder.
RickYerex wrote: Thanks, that works but only if I specify the full file name.
I'm sorry, but there's no way for us to know how your files are going to be 
named. You asked for how to check for a specific file in a specific folder, and 
that's what was provided. Otherwise, you're going to have to help us determine 
which file it is in the folder you are looking for.

Is this the only file with that specific extension in that folder?

my BAD ... so sorry ... I will try and be more specific (pun intended) in 
future. Just ASSumed wildcards would work. It is a specific file (per se`) and 
yes, there is only one " .tib " file.
Depending on which shell command you are using, they should work, you just have 
to set up the filepath correctly. you would need the full folder path of the 
parent folder + "*.tib"

e.g., in Windows, if you want to delete all of the .tib files in 
path\to\my\folder\ then

DEL "path\to\my\folder\*.tib"      
_________________
RB 2009r4 Windows XP  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 10 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