Newbie Question / remove file

I am successfully using the camera example in one of my scenes and I don’t want to leave photos stored in any directory of any device.

I am using this from the os.remove example

--forward declaration local destDir = system.DocumentsDirectory  -- Location where the file is stored local result, reason = os.remove( system.pathForFile( "Picture1.jpg", destDir ) ) -- Scene event functions   local function backButtonTouch( event ) if ( event.phase == "began" ) then audio.play( flick ) if result then     print( "Picture1 removed" ) else     print( "Picture1 does not exist", reason ) end elseif ( event.phase == "ended" ) then composer.gotoScene( "menu" ) end return true end

The simulator does not give me any error. My test device either. The picture is saved as Picture1 in the Pictures directory of my device. If I take another picture it will be saved as Picture2 … Picture3 … etc.

Could someone help me understand this?

What don’t you understand?

Hi! The photo is not deleted. I still have a file named PictureX, (X = 1,2,3,4,5,etc)
every time I take a photo.

I want to delete the “PictureX” file when the user leaves the scene using the back button and when the user touch the camera button to take a new photo.

Can anyone teach me how to do this?

I’m using the Corona sample “camera” to make my camera button works.
I read the “lfs” tutorial and to be honest I do not understand it.

Do I need to requiere “lfs” in my scene?

I don’t know which directory the Corona sample “camera” developers use to store the taken photos.

Do I need to write my own code to do this?

Do I need to make a “path folder” to store all the taken photos?

Thanks in advance.

I’m not asking anyone to write this part for me, I want to do it myself, to understand it myself, just ask for a start, something that can clarify the question of how to do this.

Please post your code here so I can take a look.

I believe by default, your photo goes to the system temporary folder (system.TemporaryDirectory) and not to the Documents folder (system.DocumentsDirectory). unless you have used some function to move the file.

Thanks for your answer. As soon as I get home I’ll upload the code.

If you want the photo to be deleted on back button press then you need to include the deletion code in the back button event. You posted…

local result, reason = os.remove( system.pathForFile( "Picture1.jpg", destDir ) )

but that will only ever delete Picture1.jpg

@wellison.maceio @adrianm
I’ll be uploading the full code on Friday when I get home.

hi,
I’ve read and reread the composer and scope topics a few times now. I don’t see anything vague, it’s seems very clear what happens and when, however, when I move buttons or text inside or outside the create/show functions, they don’t always operate the same. it’s crazy I have been struggling with this for over a week. I don’t see how the below can possibly work in any programming language…  the code below:

if (myDataTable[row.index] ~= nil) then

    local rowText = display.newText(row, myDataTable[row.index], 70, rowTitle.y, nill, 14 )

    rowText:setFillColor(0)

    sceneGroup:insert(rowText)

    count = count + 2

    print(" count = " … tostring(count))

end

yields this in the monitor/log window:

13:12:01.966   count = 2

13:12:01.976   count = 2

13:12:01.987   count = 2

13:12:01.998   count = 2

13:12:02.010   count = 2

13:12:02.030   count = 2

13:12:02.030   count = 2

13:12:02.045   count = 2

13:12:02.056   count = 2

13:12:02.078   count = 2

13:12:02.088   count = 2

13:12:02.098   count = 2

13:12:02.119   count = 2

thanks in advance for some clarity in this…  daveC

I meant to say, I don’t see how that code can’t work, increment the var count, no matter what programming language is used…

What happened here guys?
I’m confused.

Let me step in for a second. @dodi_games, it appears that @davidjcantera has posted an unrelated question/topic to your thread instead of posting to a new thread, or perhaps he was intending on replying to a different thread and accidentally posted in your thread. In Forum “lingo” this is called “Hijacking a thread” and is against the rules because it does cause confusion.  @davidjcantera, it would be helpful if you posted your question either in a new thread or if you were replying to a different thread, restate  your post there. I know you want answers and people are not going to be looking in this thread to talk about scope/tableview questions.

@dodi_games, back you the issue at hand. When you capture a new photo, we have to give it a unique name, which is why your photo number is increasing.  

If I were you, I would implement LFS and get a listing of all the files in the directory and then you can use os.remove() to remove them once you know their names. The first example in the LFS docs “Traverse a Directory” basically is the code you need. The example only prints out the file name, but you could do an 

os.remove( file )

where the print is. Now as a safety, there may be files there you don’t want to delete, so you might want to use a string.* API to try and match a pattern like Picture*.jpg. There are many different way’s to use different string.* API’s to match the string.

Rob

What don’t you understand?

Hi! The photo is not deleted. I still have a file named PictureX, (X = 1,2,3,4,5,etc)
every time I take a photo.

I want to delete the “PictureX” file when the user leaves the scene using the back button and when the user touch the camera button to take a new photo.

Can anyone teach me how to do this?

I’m using the Corona sample “camera” to make my camera button works.
I read the “lfs” tutorial and to be honest I do not understand it.

Do I need to requiere “lfs” in my scene?

I don’t know which directory the Corona sample “camera” developers use to store the taken photos.

Do I need to write my own code to do this?

Do I need to make a “path folder” to store all the taken photos?

Thanks in advance.

I’m not asking anyone to write this part for me, I want to do it myself, to understand it myself, just ask for a start, something that can clarify the question of how to do this.

Please post your code here so I can take a look.

I believe by default, your photo goes to the system temporary folder (system.TemporaryDirectory) and not to the Documents folder (system.DocumentsDirectory). unless you have used some function to move the file.