I can not delete files on windows

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Peter@multidesk.se
Posts: 136
Joined: Fri Oct 14, 2011 6:53 am

I can not delete files on windows

Post by Peter@multidesk.se » Fri Dec 15, 2017 11:08 am

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
/*Whats all the fuss with c# ?*/

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: I can not delete files on windows

Post by MaxV » Fri Dec 15, 2017 12:14 pm

Don't use spaces with names for files and folders. I suggest "Pro-cell_images" and "Cell_images".
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Peter@multidesk.se
Posts: 136
Joined: Fri Oct 14, 2011 6:53 am

Re: I can not delete files on windows

Post by Peter@multidesk.se » Fri Dec 15, 2017 1:27 pm

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
/*Whats all the fuss with c# ?*/

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: I can not delete files on windows

Post by bogs » Fri Dec 15, 2017 4:53 pm

Which version(s) of Lc and Windows?
Image

Peter@multidesk.se
Posts: 136
Joined: Fri Oct 14, 2011 6:53 am

Re: I can not delete files on windows

Post by Peter@multidesk.se » Fri Dec 15, 2017 5:38 pm

LC 9.0.0 (dp9) and widows 10.
/*Whats all the fuss with c# ?*/

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: I can not delete files on windows

Post by bogs » Fri Dec 15, 2017 5:56 pm

Well, that leaves me out, I have neither to test it on :(
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: I can not delete files on windows

Post by jacque » Sat Dec 16, 2017 5:26 pm

It could be a permissions problem. Does it work if you change the folder location to the documents folder?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Peter@multidesk.se
Posts: 136
Joined: Fri Oct 14, 2011 6:53 am

Re: I can not delete files on windows

Post by Peter@multidesk.se » Sat Dec 16, 2017 5:55 pm

No, It makes no difference.

I have also tried to turn off the UAC to see if that was the problem.
/*Whats all the fuss with c# ?*/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: I can not delete files on windows

Post by jacque » Sat Dec 16, 2017 9:13 pm

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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: I can not delete files on windows

Post by AxWald » Mon Dec 18, 2017 12:49 pm

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!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Peter@multidesk.se
Posts: 136
Joined: Fri Oct 14, 2011 6:53 am

Re: I can not delete files on windows

Post by Peter@multidesk.se » Wed Dec 20, 2017 12:29 pm

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?
/*Whats all the fuss with c# ?*/

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: I can not delete files on windows

Post by AxWald » Sun Dec 24, 2017 3:28 pm

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!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Post Reply

Return to “Windows”