Page 1 of 1

I can not delete files on windows

Posted: Fri Dec 15, 2017 11:08 am
by Peter@multidesk.se
I create a folder and copy a file to that folder, works fine.

I then try to delete the file and it works as it should on Mac but when I try this on windows, I get the result "Can not delete that file."

How is it that, and what can I do?

My code (the short version):

set the defaultFolder to specialFolderPath ("Desktop")
put the defaultFolder & "/" into tFolder
put "Pro-cell images" after tFolder
set the cTempFolder of me to tFolder

set the defaultFolder to specialFolderPath ("temporary")
put the defaultFolder & "/" into tFolder
put "Cell images" after tFolder
set the cImageFolder of me to tFolder

#######Here I copy a file into the folder Pro-cell images###########

set the defaultfolder to the cImageFolder of me
put the defaultFolder into tFolder
put url("binfile:" & the cTempFolder of me & "/" & theImage ) into url ("binfile:" & tFolder & "/" & theImage )
delete file (the cTempFolder of me & "/" & theImage)

I'm developing on Mac but unfortunately, 90% of my users have PCs, so this does not work is a big problem for me right now.



/// Peter

Re: I can not delete files on windows

Posted: Fri Dec 15, 2017 12:14 pm
by MaxV
Don't use spaces with names for files and folders. I suggest "Pro-cell_images" and "Cell_images".

Re: I can not delete files on windows

Posted: Fri Dec 15, 2017 1:27 pm
by Peter@multidesk.se
MaxV,

I can see your point, unfortunately, it does not help the fact that the file can't be deleted.

Since it is possible to copy to the folder, it is obviously found. And the file name is what it is, I don't understand why this should be a problem when it works perfectly on Mac.

PS. I changed the names so now there are no spaces :)



///Peter

Re: I can not delete files on windows

Posted: Fri Dec 15, 2017 4:53 pm
by bogs
Which version(s) of Lc and Windows?

Re: I can not delete files on windows

Posted: Fri Dec 15, 2017 5:38 pm
by Peter@multidesk.se
LC 9.0.0 (dp9) and widows 10.

Re: I can not delete files on windows

Posted: Fri Dec 15, 2017 5:56 pm
by bogs
Well, that leaves me out, I have neither to test it on :(

Re: I can not delete files on windows

Posted: Sat Dec 16, 2017 5:26 pm
by jacque
It could be a permissions problem. Does it work if you change the folder location to the documents folder?

Re: I can not delete files on windows

Posted: Sat Dec 16, 2017 5:55 pm
by Peter@multidesk.se
No, It makes no difference.

I have also tried to turn off the UAC to see if that was the problem.

Re: I can not delete files on windows

Posted: Sat Dec 16, 2017 9:13 pm
by jacque
Do you see anything if you check for an error message:

Code: Select all

delete file (the cTempFolder of me & "/" & theImage)
answer the result && the syserror

Re: I can not delete files on windows

Posted: Mon Dec 18, 2017 12:49 pm
by AxWald
Hi,

I assume you have a minor mistake somewhere in your code; carefully testing "the result" and using the debugger should uncover it quite easily.

To be sure it isn't a LC bug I wrote this short button handler - it creates a file in ./temp, copies it to ./docs, then deletes both of those again.
Works flawlessly in Win 10 pro64 (high AC control) & LC 6.7.10.

You may try it to find out if your Win versions/ LC version behaves differently:

Code: Select all

on mouseUp
   put (specialfolderpath("temporary") & "/") into myTempFolder
   put (specialfolderpath("documents") & "/") into myDocFolder   
   put "_XTest.txt" into myFile
   put the long date && the long time into myData
   
   put myData into URL ("binfile:" & myTempFolder & myFile)
   -- result check here:
   put the result into myVar
   breakpoint
   --  => "XTest.txt" is now in "C:\Users\myName\AppData\Local\Temp"
   
   put URL ("binfile:" & myTempFolder & myFile) into URL ("binfile:" & myDocFolder & myFile)
    -- result check here:
   put the result into myVar
   breakpoint
   --  => "XTest.txt" is now in "D:\Users\myName\Documents\" also
   
   delete file (myTempFolder & myFile)
    -- result check here:
   put the result into myVar
   breakpoint
   --  =>  "C:\Users\myName\AppData\Local\Temp\_XTest.txt" got deleted
   
   delete file (myDocFolder & myFile)
    -- result check here:
   put the result into myVar
   breakpoint
   --  =>  all instances of "_XTest.txt" are cleared now
end mouseUp
Have fun!

Re: I can not delete files on windows

Posted: Wed Dec 20, 2017 12:29 pm
by Peter@multidesk.se
Now it works to delete the file!

The file was still in use so I had to close it before I could remove it. :)

Now I have another problem.
When I set the "fileName" of my image, I get "could not open image".

There is nothing wrong with the pathway, this seems to be a similar issue to the previous problem, except that it can not be resolved by closing the file or folder.

if I copy the pathway and then set the property inspector for the image to it, nothing happens. This applies to all images that I somehow handle in the application.

For example, if I set the pathway in the above way to a desktop image before I use it in the application, it works, but after the program has copied it, it will not work.

And this is still just a Windows issue, Why do not everyone use a Mac. :wink:


Suggestions, anyone?

Re: I can not delete files on windows

Posted: Sun Dec 24, 2017 3:28 pm
by AxWald
Hi,

maybe I misunderstand, but this works flawlessly here:

Code: Select all

on mouseUp
   --  you need an image area named "test_img" besides this btn!
   put specialFolderPath("Desktop") & "/Saved Pictures/" into myPath
   put specialFolderPath("Desktop") & "/Test_Picts/" into myTestPath
   put "P8010001.JPG" into pict1
   put "P8010002.JPG" into pict2
   
   if (pict1) is in the fileName of img "test_img" then
      set the fileName of img "test_img" to (myPath & pict2)
      answer "This the original pict from " & CR & (myPath & pict2) \
            with "Cancel" and "Copy it!"
      if it is "Cancel" then exit mouseUp
      set the fileName of img "test_img" to empty
      put URL ("binfile:" & myPath & pict2) into URL ("binfile:" & myTestPath & pict2)
      set the fileName of img "test_img" to (myTestPath & pict2)
      answer "This the freshly copied pict from " & CR & (myTestPath & pict2)
      
   else
      set the fileName of img "test_img" to (myPath & pict1)
      answer "This the original pict from " & CR & (myPath & pict1) \
            with "Cancel" and "Copy it!"
      if it is "Cancel" then exit mouseUp
      set the fileName of img "test_img" to empty
      put URL ("binfile:" & myPath & pict1) into URL ("binfile:" & myTestPath & pict1)
      set the fileName of img "test_img" to (myTestPath & pict1)
      answer "This the freshly copied pict from " & CR & (myTestPath & pict1)
   end if
end mouseUp
It switches between the picts, copies them (overwrites if neccessary), shows the new ones, no problems at all.
And this is still just a Windows issue,
Quite sure this is not a Windows issue. You might want to check your code again.
Why do not everyone use a Mac.
There's still a "rest of us", capable of "thinking different", that doesn't like to have a "big brother" in Cupertino to tell us how beautiful life is in an overprized iJail ;-)))

Have fun!