[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to delete a file in Win XP

Mateusz Winiarski

7/9/2008 10:55:00 AM

Greetings,

How to delete a file in Win XP ?

code:

File.chmod(0644, file)
File.delete(file)

does not working.

THX
14 Answers

Dave Bass

7/9/2008 11:39:00 AM

0

Mateusz Winiarski wrote:
> How to delete a file in Win XP ?

In what way doesn't it work? What error message are you getting?

I've had a problem with deleting opened files on WinXP (using
File.open). They're supposed to be closed automatically but that doesn't
necessarily happen immediately, but when Ruby or the OS gets around to
it. The answer is to close the file explicitly.

Another thing to look at is IO.sync.

Does that help at all?

Dave
--
Posted via http://www.ruby-....

Phlip

7/9/2008 11:45:00 AM

0

MAwiniarski wrote:
> Greetings,
>
> How to delete a file in Win XP ?
>
> code:
>
> File.chmod(0644, file)
> File.delete(file)
>
> does not working.

unlink ?

like the File documentation says?

Roberto Casadei

7/9/2008 11:58:00 AM

0

Mateusz Winiarski wrote:
> Greetings,
>
> How to delete a file in Win XP ?
>
> code:
>
> File.chmod(0644, file)
> File.delete(file)
>
> does not working.
>
> THX

That works to me.

In both function calls you should get the number of processed files or
an exception..
The 'file' var must be a file path, not a File object.
--
Posted via http://www.ruby-....

Serg Koren

7/9/2008 4:27:00 PM

0

When all else fails, try using the full path to the file. You're
probably in the wrong directory.
This works for me.

On Jul 9, 2008, at 6:51 AM, MAwiniarski wrote:

> Greetings,
>
> How to delete a file in Win XP ?
>
> code:
>
> File.chmod(0644, file)
> File.delete(file)
>
> does not working.
>
> THX
>


Mateusz Winiarski

7/9/2008 6:12:00 PM

0

1. I'm in a proper directory (using: puts Dir.entries(Dir.pwd)
2. File do not need to be closed, because it haven't been open (it's
just file in a folder)
3. Error message:
Errno::EACCES: Permission denied - file
4. I've used chmod in previous line:
File.chmod(0644, file)
chmod return flag: 1 (one)
5. Using File.delete or File.unlink gives same error message

On Jul 9, 6:26=A0pm, Serg Koren <myEmailLi...@comcast.net> wrote:
> When all else fails, try using the full path to the file. =A0You're =A0
> probably in the wrong directory.
> This works for me.
>
> On Jul 9, 2008, at 6:51 AM, MAwiniarski wrote:
>
> > Greetings,
>
> > How to delete a file in Win XP ?
>
> > code:
>
> > File.chmod(0644, file)
> > File.delete(file)
>
> > does not working.
>
> > THX
>
>

Luis Lavena

7/9/2008 10:12:00 PM

0

On Jul 9, 8:12 pm, MAwiniarski <MAwiniar...@gmail.com> wrote:
> 1. I'm in a proper directory (using: puts Dir.entries(Dir.pwd)
> 2. File do not need to be closed, because it haven't been open (it's
> just file in a folder)
> 3. Error message:
>    Errno::EACCES: Permission denied - file
> 4. I've used chmod in previous line:
>    File.chmod(0644, file)
>    chmod return flag: 1 (one)
> 5. Using File.delete or File.unlink gives same error message
>

File.chmod has no effect on Windows.

Can you ensure that, from the command line, safely remove that file?
Even if not you the one that openned the file, maybe other part of the
OS are locking it so you can't perform the delete operation safely.

HTH,
--
Luis Lavena

Pablo Q.

7/9/2008 10:40:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

Another solution could be use a system call:


`DEL #{file}`
or
system("DEL #{file}")

it returns true or false.


2008/7/9 Luis Lavena <luislavena@gmail.com>:

> On Jul 9, 8:12 pm, MAwiniarski <MAwiniar...@gmail.com> wrote:
> > 1. I'm in a proper directory (using: puts Dir.entries(Dir.pwd)
> > 2. File do not need to be closed, because it haven't been open (it's
> > just file in a folder)
> > 3. Error message:
> > Errno::EACCES: Permission denied - file
> > 4. I've used chmod in previous line:
> > File.chmod(0644, file)
> > chmod return flag: 1 (one)
> > 5. Using File.delete or File.unlink gives same error message
> >
>
> File.chmod has no effect on Windows.
>
> Can you ensure that, from the command line, safely remove that file?
> Even if not you the one that openned the file, maybe other part of the
> OS are locking it so you can't perform the delete operation safely.
>
> HTH,
> --
> Luis Lavena
>
>


--
Pablo Q.

Axel

7/10/2008 5:46:00 AM

0


- Maybe, the "rights" of your ruby application are not set
appropriate. For example, if you have different user accounts on your
machine (usually, the users have restricted rights), they can only
delete files in certain directories. This is only a simple example,
there are more difficult possibilies.

- Can you delete the files using the Windows Explorer? (Starting it
from within the same user account as you run your ruby application.

Axel

Mateusz Winiarski

7/10/2008 5:51:00 AM

0

using: system('del ' + filename)

output is: .The process cannot access the file because it is being
used by another process.

How to unlink file from all processes ??

On 10 Lip, 00:39, "Pablo Q." <paqs140...@gmail.com> wrote:
> Another solution could be use a system call:
>
> `DEL #{file}`
> or
> system("DEL #{file}")
>
> it returns true or false.
>
> 2008/7/9 Luis Lavena <luislav...@gmail.com>:
>
>
>
> > On Jul 9, 8:12 pm, MAwiniarski <MAwiniar...@gmail.com> wrote:
> > > 1. I'm in a proper directory (using: puts Dir.entries(Dir.pwd)
> > > 2. File do not need to be closed, because it haven't been open (it's
> > > just file in a folder)
> > > 3. Error message:
> > > =A0 =A0Errno::EACCES: Permission denied - file
> > > 4. I've used chmod in previous line:
> > > =A0 =A0File.chmod(0644, file)
> > > =A0 =A0chmod return flag: 1 (one)
> > > 5. Using File.delete or File.unlink gives same error message
>
> > File.chmod has no effect on Windows.
>
> > Can you ensure that, from the command line, safely remove that file?
> > Even if not you the one that openned the file, maybe other part of the
> > OS are locking it so you can't perform the delete operation safely.
>
> > HTH,
> > --
> > Luis Lavena
>
> --
> Pablo Q.

Mateusz Winiarski

7/10/2008 7:10:00 AM

0

deleting in windows explorer works fine in the same account

On Jul 10, 7:46 am, Axel <a99.googlegroups....@dfgh.net> wrote:
> - Maybe, the "rights" of your ruby application are not set
> appropriate. For example, if you have different user accounts on your
> machine (usually, the users have restricted rights), they can only
> delete files in certain directories. This is only a simple example,
> there are more difficult possibilies.
>
> - Can you delete the files using the Windows Explorer? (Starting it
> from within the same user account as you run your ruby application.
>
> Axel