playMaker

Author Topic: DeleteFile  (Read 1278 times)

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
DeleteFile
« 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/

Adamantius

  • Playmaker Newbie
  • *
  • Posts: 5
    • 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: 13323
  • 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

  • Playmaker Newbie
  • *
  • Posts: 22
    • 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: 13323
  • 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

  • Playmaker Newbie
  • *
  • Posts: 22
    • 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: 13323
  • 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

  • Playmaker Newbie
  • *
  • Posts: 22
    • 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: 13323
  • 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

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