Whats the best way to check weather a file exists online, or not?

Hi!
I need to show an Image File in my app which may have different sizes. _1.jpg, _2.jpg and so on.. If, for example, _2.jpg does not exist, I have to take _1.jpg.
So my question is: is there a better way instead of making/allocating a pic and asking pic != nil ?
thx!
alex

Hi Alex -
The subject line says "file exists online, or not?". Are you trying to check existence at a network site, or the local file system? I'll cover the local fs first, since that's the easiest. If you need to search a remote site, I think we'll need some more details.
Assuming an iPhone project (not specified, but your usual topic), NSFileManager will probably be all you need unless the files are localized and/or in the application bundle, in which case you'll want NSBundle. For example, say you're storing all the jpg's in the user's cache directory:
#define MAXFN 5
// return nil or the path to the file with the highest numeric suffix
- (NSString)getPathForBestFile:(NSString)baseName extension:(NSString*)ext {
NSString *bestFilePath = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
// locate the user's cache directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDirectory = [paths objectAtIndex:0];
NSLog(@"cacheDirectory=%@", cacheDirectory);
// loop through file names with numeric suffixes
for (int i = 1; i <= MAXFN; i++) { />/
NSString *fileName =
[NSString stringWithFormat:@"%@_%d.%@", baseName, i, ext];
NSString *filePath =
[cacheDirectory stringByAppendingPathComponent: fileName];
NSLog(@" filePath=%@", filePath);
if ([fileManager fileExistsAtPath:filePath])
bestFilePath = filePath;
return bestFilePath;
If you need to use NSBundle, see pathForResource:ofType:. If you need to determine the existence of a file at a network site, please give us some details about the kind of server and how much you'll know about the possible file locations.
Hope that helps!
- Ray

Similar Messages

  • Whats the best way to check table before form deletion or update ?

    Hi, I have a func_staff table made up of a composite key - func_no and staff_id. I have a form where the datablock references this table.
    I need to be able to check that before a func_no and staff_id combination on the form are written to the database that that combination does not already exist in the table.
    What would be the code for that ? I've tried stuff like IF EXIST statements and even a select statement but I totally worded it it wrongly.
    To DELETE an entry in that same table, would the best way to be create an LOV for both func_no and staff_id, the problem with that would be if a user selected a combination that does not exist ? Could I create a combined LOV that would populate each field ?? (this way I could be 100% sure that the selected combination is valid)
    Thanks Peeps.

    hi,
    you can try and use the count(*), before deleting and updating
    lets say
    select count(*)
    into l_count
    from table_name
    where column1 = :block.column1
    and column2 = :block.column2;
    if l_count <> 1
    then
    insert into..........
    else
    show error message;
    raise form trigger failure;
    end if;
    similarly u can use l_count before deleting.
    regards,
    Mayank

  • Whats the best way to check the speed of my macbook Pro

    Hi people.
    I just wanted to get some advice on how my Mac is running, as i think it has become slower since i bought it and wondered if it is anything i have done or should be doing
    First of all, i have a MBP bought mid 2011, has thunderbolt port, its 2.3Ghz Intel i5, 4GB 1333Mhz DDR3, 320Gb HD and now running Mountain Lion.
    When i first got it i thought it was quicker than anything i have used previously, an example would be when i click to open an apple program e.g. iphoto, the icon jumped up and then seconds later it was open. Now any program i try to open, it seems to take much longer, it bounces for a while and then finally opens.
    I have not got any clutter on the laptop, i keep all my files on a network hard drive. The only thing i have is 80Gb of photos stored under iphoto and i have Windows XP running on a 40Gb partition using Bootcamp.
    I am thinking about getting rid of the XP on my mac to see if it helps, but thought i would ask here first. I need XP as it allows me to run programs which dont support Apple OS X.
    I was also wanting to know the best way to store photos, would i be able to store the photos on my network drive and have iphoto work exactly the same..?
    Help much appreciated.
    Thank you.

    Hi people.
    I just wanted to get some advice on how my Mac is running, as i think it has become slower since i bought it and wondered if it is anything i have done or should be doing
    First of all, i have a MBP bought mid 2011, has thunderbolt port, its 2.3Ghz Intel i5, 4GB 1333Mhz DDR3, 320Gb HD and now running Mountain Lion.
    When i first got it i thought it was quicker than anything i have used previously, an example would be when i click to open an apple program e.g. iphoto, the icon jumped up and then seconds later it was open. Now any program i try to open, it seems to take much longer, it bounces for a while and then finally opens.
    I have not got any clutter on the laptop, i keep all my files on a network hard drive. The only thing i have is 80Gb of photos stored under iphoto and i have Windows XP running on a 40Gb partition using Bootcamp.
    I am thinking about getting rid of the XP on my mac to see if it helps, but thought i would ask here first. I need XP as it allows me to run programs which dont support Apple OS X.
    I was also wanting to know the best way to store photos, would i be able to store the photos on my network drive and have iphoto work exactly the same..?
    Help much appreciated.
    Thank you.

  • Whats the best way to save large folders/files on multiple dvds?

    hi,
    A quick question about the best way to save to dvd(4.7gb disc) a large number of folders/files.I've got about 30-40gb of stuff to save from mp3 sample files through to logic audio files.I already have them saved to another HD but i just want to be extra safe and have another back up.In the past i've just saved it disc by disc creating each folder as i go dragging the appropriate folder across.I was just wondering whether there was an easier way than this.May be an application where i can drag all the files and it will sort and save everything for me much like the way itunes now saves/backups files.
    thanks
    darren

    Hi darrenz,
    if you have Toast you can save your stuff using Toast. There's a great option within Toast. You need to select the Data tab and choose "Mac only". Then just drag all the stuff you want to burn to the Toast window and it will automatically ask for another DVD until everything is burnt. After that all your DVDs will have a Toast Restore app on them. It lets you select what you want to restore and will tell you which DVDs to insert. Here's a screenshot I found by googling: http://www.macworld.com/images/content/2005/08/19/toast7restore.jpg
    Have fun!
    Björn

  • HT2506 Whats the best way to open an ICO file?

    Anyone know how to successfully open an ICO image file on a Macbook Pro? Thanks

    I think this will work:
    http://iconverticons.com/

  • Mac Pro won't start up.  What's the best way to check the power supply?

    Hello. I'm having a severe problem with my 2007 Mac Pro. The symptoms are very easy to describe. The computer apparently shut itself off overnight, and when I press the power button to turn it on, absolutely nothing happens. No lights, no chime, no signs of any power whatsoever in the computer. I have never had major problems with the computer before. (Although I had recently noticed some minor skipping problems with streaming videos and Firefox had started hanging occasionally.)
    So far, I have checked the power cable and the power outlet. I have also reset the SMC (holding in the Power button for 5 seconds with the unit unplugged). I am unable to see any light in the diagnostic LEDs (including LED 1) when I press the DIAG_LED button on the logic board.
    While I welcome other suggestions, all I can figure is that this is either a power supply problem or a major logic board failure, but I don't know which. I have a multimeter and would like to test very directly if the power supply is the problem, because they are very expensive and obviously I do not want to order a replacement supply if it would not fix the computer. Does anyone know what the best way to test the supply directly is? What pins on what cable should I test, and what voltage should I look for?
    Also: No the computer is not under any warranty. If at all possible, I would like to fix this myself. Thanks for any help you can give.

    Well, I may have found the answer to my question as to why replacing the fuse dows not seem to be encouraged. I cut out the failed fuse (fast fuse, ceramic, 16 Amp 250V), and replaced it with another that was as close to it in spec as I could find (15 A instead of 16). Then I put the supply back in the case.
    When I tried to plug it in, I got an immediate spark, followed by an acrid smell from the power supply. Later inspection revealed that the new fuse blew, as did another component nearby (not sure what it was) where I could see blackening and the smell was concentrated. At this point, I would consider myself lucky if the power supply didn't take anything else on the computer out with it.
    Lesson learned; will try a new power supply and go from there.

  • I am getting pop ups on safari and firefox lately and am worried i may have malware or something now on my computer doing this. What is the best way to check this out for sure and remove it?

    I am getting pop ups on safari and firefox lately and am worried I may have malware or something now on my computer doing this. What is the best way to check this out for sure and remove it?

    Please review the options below to determine which method is best to remove the Adware installed on your computer.
    The Easy, safe, effective method:
    http://www.adwaremedic.com/index.php
    If you are comfortable doing manual file removals use the somewhat more difficult method:
    http://support.apple.com/en-us/HT203987
    Also read the articles below to be more prepared for the next time there is an issue on your computer.
    https://discussions.apple.com/docs/DOC-7471
    https://discussions.apple.com/docs/DOC-8071
    http://www.thesafemac.com/tech-support-scam-pop-ups/

  • I want to connect a Mac mini to a Samsung 40", Whats the best way to do this?

    I want to connect a Mac mini to a Samsung 40" LED tv to use as the monitor, whats the best way of doing this?

    Understand that there is one HDMI port on your TV that is specifically designated for PC connectivity. The order that the TV or Mini are powered on may determine your results. For your specific TV model, check buyer reviews on Amazon or elsewhere that can include optimum TV/Computer settings adjustment for improved viewing results.

  • Whats the best way to stream videos?

    whats the best way to stream video thru plumtree portal?What all it requires? (technology/application/server/plumtree development?)

    Hello Kuljit,
    For the windows platform you could set up Windows Media services. It can be configured to play all sorts of media files. I created a "radio station" portlet that multiple channels and from the portal I could select a drop down and the station would play that stream. I would make sure that media services are not being gatewayed and that anyone that can see your portal can see the videos. Here is my html that I made a portlet out of: This will not show the video window. You can increase the size of the object to show the video window with controls. Check out MSDN online for configuration of the <object>
    <FORM NAME="streamForm"> <INPUT NAME="btnPlay" TYPE="Button" VALUE="Play" onclick="MediaPlayer1.controls.Play();"> <INPUT NAME="btnStop" TYPE="Button" VALUE="Stop" onclick="MediaPlayer1.controls.stop();"> <select name="musicGroup" onChange="changeStream()"> <option value="">-- Select --</option> <option value="barenakedladies">Barenaked Ladies</option> <option value="pinkfloyd">Pink Floyd</option> </select> </FORM>
    <OBJECT CLASSID="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" ID="MediaPlayer1" height="0" width="00"> <PARAM NAME="Name" VALUE="MediaPlayer1"> <param name="uiMode" value="invisible"> <PARAM NAME="TransparentAtStart" Value="true"> <PARAM NAME="AutoStart" Value="true"> <PARAM NAME="AnimationatStart" Value="false"> <PARAM NAME="ShowControls" VALUE="0"> <PARAM NAME="autoSize" Value="false"> <PARAM NAME="displaySize" Value="0"></OBJECT><script language="javascript">function changeStream(){ df = document.streamForm; if(df.musicGroup.selectedIndex != 0) {  MediaPlayer1.url = "mms://MBRUCELT-W3k/"+df.musicGroup[df.musicGroup.selectedIndex].value; } }</script>
    This works for the latest version of Window Media Player. The mms:// in my script is a call to Windows Media Services. That is the part that should be accessible from outside the portal.
    HTH,
    Michael [email protected]

  • When travelling and using 3G what the best way to turn off all internet connections except web browser on a Mac pro?

    When Travelling and using a 3G mobile stick for internet connection My MacPro burns through a lot of expensive connection data time doing background stuff such as checking messages, email, ungrades etc. Whats the best way to turn all this off so that intenet is only accessed when I request it?
    Thanks

    To turn off iMessages see this thread - https://discussions.apple.com/thread/4504796?start=0&tstart=0 
    For iCloud, read the article - http://support.apple.com/kb/PH2613 

  • HT3819 I have 2 Ipod touch's, one a 64gb and one an 8gb.  Whats the best way to use them both on the same itunes account?

    I have 2 Ipod touch's, one a 64gb and one an 8gb.  Whats the best way to use them both on the same itunes account?

    Click here for options.
    (64410)

  • What is the best way to keep my personal files stored in iCloud separate from my work-related files?

    What is the best way to keep my personal files stored in iCloud separate from my work-related files? It seems that I'm not allowed to link my iPad mini and my work iMac using two different accounts, so I'm wondering how to make my single personal account work for both, while keeping personal vs work files reasonably separated.
    Thanks for any suggestions.

    Is it possible for you to upgrade your account to iCloud Drive? That would mean, all Macs upgraded to Yosemite, and all mobile devices to iOS8?
    See:  iCloud Drive FAQ and iCloud: About using iWork for iOS and iCloud
    In iCloud Drive you could create two separate custom folders, one for work documents and one for private documents and organize your documents there.  Don't use the app specific folders (Keynote, Pages, Numbers, ...) , because you can only create one level of folders inside these folders.

  • Whats the best way to transfer everything from my old macbook pro to a new mac mini, i have a external hard drive which i backup to regularly via time capsule

    whats the best way to transfer everything from my old macbook pro to a new mac mini, i have a external hard drive which i backup to regularly via time capsule

    Check out > OS X Lion: How to use Migration Assistant to transfer files from another Mac

  • Wipe my hard drive clean except for the OS whats the best way?

    I need to wipe my hard drive clean except for the OS whats the best way?

    From Kappy (note: with this method, you will need to update to the present OS version using the appropriate Combo Update from Apple Downloads.)
    Boot from the OS X Installer Disc One that came with the computer. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities (Installer menu if using Panther or Jaguar) menu. After DU loads select the startup volume from the left side list then click on the Erase tab. Set the format type to Mac OS Extended (Journaled) then click on the Options button. Select the one pass Zero Data option and click on the OK button. Then click on the Erase button.
    Note: You can skip the Zero Data option if you are not concerned about removing sensitive personal data from the hard drive. If you choose to skip this part of the process then it is possible for others to recover data from the hard drive. The Zero Data procedure will prevent others from getting access to your personal information.
    This process will take 30 minutes to several hours depending upon the size of the hard drive. After formatting has completed quit DU and return to the installer. Now complete the OS X installation. At the completion of the installation do not restart the computer. Instead just shut it off. The next user will be presented with the Setup Assistant when they turn on the computer just as it would if new out of the box.
    https://discussions.apple.com/message/12364050?messageID=12364050#12364050

  • When I'm done with my fcp sequence, whats the best way to get it to dvd?

    When I'm done with my fcp sequence, whats the best way to get it to dvd?

    The advice to go to Compressor left out the part that you may want to convert your audio to AC3 becaus ethe MPEG2 bitrate is probably too high for DVD specs.
    This method is in the DVDSP manual and it's in the Compressor manual, both difficult to locate, but easily searchable.
    Here's what I'd do: Export the timeline form FCP in the native sequence settings, self-contained. Bring that self-contained movie into DVDSP and let DVDSP handle the transcode.
    The advice to go to iDVD is even easier.
    bogiesan

Maybe you are looking for

  • Error in writting query

    iam having this following query in which FirstName,MiddleName,LastName columns in tables and their datatype is nvarchar2 i am writing this query 1) SELECT NVL(Employee_Mst.FirstName, '  ' ) || ' ' *|| NVL(Employee_Mst.MiddleName, ' ') || ' '* *|| NVL

  • Importing Safari bookmarks into IE on Windows XP Pro

    I was just given an old PC by my mom. I'm using RDC to control it with my iBook (very nifty - I can sit down here in the living room and control that dumb PC upstairs!). Anyway, is there a way to import my Safari bookmarks into Internet Explorer on t

  • Change the default stack size in the java.exe file

    Does anyone know how to change the default stack size of the jvm? I'm having problems with my stack. Is there anyway I can change it. I found a tool editbin.exe which is shipped with Visual c++, however I don't have the tool. Thanks, William

  • Georeference cartesian co-ordinates to standard co-ordinate system

    We have set of old maps which do not follow any standard co-ordinate system and they are just cartesian grid co-ordinates (for example lat,long 40.733828,-73.988414 corresponds to cartesian co-ordinates 1610350, 1114450) . I want to explore a possibi

  • How to set defaults?

    I need to permanently set the default for my Mail program to NOT delete my mail off the original server (Yahoo) after one week. This happens every three months: Mail crashes. That's life. I can't open Mail without resetting the Connection (it just cr