playMaker

Author Topic: DeleteFile[SOLVED]  (Read 2578 times)

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
DeleteFile[SOLVED]
« on: March 22, 2016, 03:39:29 PM »
Delete a file.

Includes a secure delete so you can overwrite onto the file as many times as you feel the need.

On ecosystem or https://snipt.net/dudebxl/
« Last Edit: April 02, 2019, 04:31:09 AM by jeanfabre »

Adamantius

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Re: DeleteFile
« Reply #1 on: March 23, 2016, 01:37:57 AM »
Dudebxl,

Thanks for all the amazing Actions, really appreciate the work you put in. : )

Just a question though, I'm noticing that your more recent actions don't seem to work with Unity 4.6. Are your actions now strictly for Unity 5 or do you have plans to make them work for Unity 4.6 down the line?

I was thinking of upgrading to Unity 5 in the future but I'm comfortable with 4.6 for now and it would be great to be able to use all your new actions with it.


: )

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: DeleteFile
« Reply #2 on: March 23, 2016, 06:14:10 AM »
Most should work in 4.6.

Just give it a try. I have not tested in 4.6 so I just put 5 as i know they work in 5

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14703
  • Official Playmaker Support
    • View Profile
Re: DeleteFile
« Reply #3 on: March 30, 2016, 04:00:47 AM »
Hi,

 if you see actions that do not work on 5, let us know, sometimes it's easy to provide a modification that makes it compatible with all version.

Bye,

 Jean

Farwest

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 52
    • View Profile
Re: DeleteFile
« Reply #4 on: July 07, 2018, 06:22:04 AM »
Hi,
Is it possible if you can you check this "DeleteFile"? Although I enter the correct filepath, it does not delete the file and throws fail event.

The path I try to delete is:
Application.persistentDataPath + "/" + filename.Value
I use "build string" action to form this FilePath and use the variable in DeleteFile.

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14703
  • Official Playmaker Support
    • View Profile
Re: DeleteFile
« Reply #5 on: July 11, 2018, 12:23:47 AM »
Hi,

 the way to debug this is to logs your variable content.

 so first thing, build the string of your filepath into a fms String and then use the Log action to output it in the Unity console. Then you copy this and use it in your OS explorer or finder and see if it resolves to the right file or not, if it does, then we have a problem, if it doesn't it's your filepath that's wrong.


 bye,

 Jean

Farwest

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 52
    • View Profile
Re: DeleteFile
« Reply #6 on: July 11, 2018, 07:08:20 AM »
Hi,
Thank you for the feedback. Filepath works. I successfully deleted the file when entered the exact FilePath in my OS. Problem is on my side.

Maybe I had a wrong perception by using Application.persistentDataPath according to here:

https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

However, I still have a problem and I would like your opinion to solve it.

What I try to achieve is, using a "filepath" that can be universal. Surely, the customer's Username will be different. Possibly, the C: or D: device will be different. Therefore, using the exact Filepath in my OS won't be helfpul, but I need to write a name that, Deletefile finds the place where Unity is saving the Files (I use Binary Save-Load actions actually, when Saving it uses:
FileStream file = File.Create(Application.persistentDataPath + "/" + filename.Value); as filepath).
I will be happy if you can help me to solve my problem, so I can Delete the Save files too. 

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14703
  • Official Playmaker Support
    • View Profile
Re: DeleteFile
« Reply #7 on: July 18, 2018, 01:47:24 AM »
Hi,

 persistent datapath is the way to go indeed.

you'll need to debug the exact file path that are being used to understand what's going on.

for example, what is your exact Application.persistentDataPath value, maybe it has already the / at the end, etc etc

 Bye,


Jean

Farwest

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 52
    • View Profile
Re: DeleteFile
« Reply #8 on: August 17, 2018, 08:08:30 AM »
Thanks, I solved my problem by replacing "pathToFile" with BinarySave's "Application.persistentDataPath + "/" + filename.Value" in the script body, also I added public string Filename, thus it is solved, now I can delete my Binary Saves successfully.

However outside this issue, still I don't know how to write a correct "FilePath" to Delete a File (is it "C:\Users\[user]\AppData\...?") other than replacing the Filepath with Application.persistentDataPath or anything specific, I hope somebody can explain.

Briefly, the question is, what should we write for Filepath, should it be "C:\Users\[user]\" or something else, because we can't write explicit filepath as we have in our OS, but it must be universal.
« Last Edit: August 17, 2018, 08:11:23 AM by Farwest »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14703
  • Official Playmaker Support
    • View Profile
Re: DeleteFile
« Reply #9 on: August 23, 2018, 12:10:48 AM »
Hi,

 there are some shortcuts to these paths, check this post, it features a list of all the resulting paths given the choices:

https://stackoverflow.com/questions/895723/environment-getfolderpath-commonapplicationdata-is-still-returning-c-docum/3000373

Bye,

 Jean

Farwest

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 52
    • View Profile
Re: DeleteFile
« Reply #10 on: August 29, 2018, 08:23:20 AM »
Thanks, it is an helpful article

amoraleite

  • Playmaker Newbie
  • *
  • Posts: 11
    • View Profile
Re: DeleteFile
« Reply #11 on: March 30, 2019, 07:29:13 AM »
Guys I would like to revive this post because I have a doubt that looks like the discussion here.

I'm a newbie on code, playmaker help me a lot with the code less :)

My problem:
I have photos on my application folder.
I need a button that delete theses photos one by one.


So I put on my main FMS the action AplicationGetPersistentDataPath. And it's work. Because my variable string show the right path to the application, or almost, missing the final folder "Screenshoots".
I created a button with the action Delete and I'm used the string variable with the path that a mentioned above.

But the path are incomplete... So the action can't locate the photo and delete.

I have a script the save the image with name Screenshoot + number + date ie: (Screenshot_2019-03-27_11-30-08)

My questions:
How can I specific the file to the action delete?
The photos are locate in a folder called Screenshoots, How can I add this on the path?

Thank you guys and sorry but I''m not a programmer... I'm an artist that love playmaker.






jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14703
  • Official Playmaker Support
    • View Profile
Re: DeleteFile
« Reply #12 on: April 01, 2019, 03:56:40 AM »
Hi,

 you need to debug this on your computer first.

 locate where is your application persistent folder for that app on your hardisk ( using the action AplicationGetPersistentDataPath will tell you, you can log this on your game screen if you want or do that from the editor)

then,

- check the content and make sure your files are where you think they are ( checking manually on your OS explorer).

- debug log the path you are building to delete them, and copy paste that into a reguler text editor, make sure it's valid, and use that in your OS explorer to see if it points to that file you want to delete. if it does, then it should work, else fix the logic that builds that wrong filename path.

 let me know your findings after you've done the above.

 Bye,

 Jean

amoraleite

  • Playmaker Newbie
  • *
  • Posts: 11
    • View Profile
Re: DeleteFile
« Reply #13 on: April 01, 2019, 06:51:02 AM »
Hi Jean!

Thank you for your reply!
Works Great!
The Action get path tell me where the files are.

But to delete the specific file is more complicate, because the file are names that receive date and hour informations, so the name are is hard to track.

What I did is to use an external code that delete all directory and recreate this directory in same time. A little script that I put into a Unity button that do job for me. I access the script via Unity onclick button. It's solve for now :)

But thank you very much for your help! All the informations contribute to grow my knows about the programation. :)