File handling problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: File handling problem

  1. #1
    Join Date
    Dec 2012
    Posts
    4

    File handling problem

    Hy all!

    i wrote an app which opens pictures stored on hard drive, to a picture album, and what i want is that when i want to save the album, cannot overwrite the existing files, because "they are in use by another process" (by the app itself), so is there any method to "dispose" the files from the app first, to be able to delete/overwrite them?

    thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,873

    Re: File handling problem

    Name them as something else, close all connections to the loaded picture. Later, rename the changed file after you delete the original.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Dec 2012
    Posts
    4

    Re: File handling problem

    the problem is that the save is done and the name is given by the same for loop, automatically, because on load to be able to be identified by the name and loaded in the correct object array

  4. #4
    Join Date
    Dec 2012
    Posts
    4

    Re: File handling problem

    and if i load an album, add pictures to it, and then save it back, the old pictures has to be overwritten, but they are also opened by the app, thats my problem

  5. #5
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,781

    Re: File handling problem

    Not sure how you may be doing this but if you are not editing the pictures then there is no reason to save one that already exists. That would just slow down the program and serve no real purpose. You should add some code to see if the picture already exists at the given location and if so then do not try to save it again,

    I think if I were going to do an album I would have all my pictures stored in one location and then use a text file for each album to hold the filenames of the pictures and the order they should appear. This would mean that I would not have to save images when they are placed in a album just the filename and would allow the same picture to appear in more than one albumn or more than once int he same album while not needing to have more than one copy of the actual picture.
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Dec 2012
    Posts
    4

    Re: File handling problem

    i`ve made as you said, to check if the picture exists, and save only the non-existent images, works great but it also represents an issue:

    the albums and the pictures are stored in an object array, something like this: albums(album_id, picture_id) as object

    the files are saved as (album_id, & "_" & picture_id, & ".jpg"), so the first picture of the fist album is 0_0.jpg

    the problem with your method is that if i delete a picture, the id of that picture will get the id of the next picture, and so, and if i save the album without the picture i`ve deleted, it must overwrite the name of all pictures after the deleted one, (open them for write), but they are still open by the app itself, so the same problem occurs again.

    Sorry for my bad english , im from Romania

  7. #7
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,781

    Re: File handling problem

    I think it would make more sense to have a seperate file for the album that holds the filenames of the pictures that are to be included. Should be very easy to do and would solve your issues as well as allowing you to be able to add the same photo to more than 1 album without needing to have more than one copy of the image. Seems like a no brainer.
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,873

    Re: File handling problem

    Adding: The text file would be like a BATCH FILE that you can call when you want the operation to run. Run upon exit, if needed.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center