Greetings,
How to delete a file in Win XP ?
code:
File.chmod(0644, file)
File.delete(file)
does not working.
THX
Greetings,
How to delete a file in Win XP ?
code:
File.chmod(0644, file)
File.delete(file)
does not working.
THX
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-forum.com/\.
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?
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-forum.com/\.
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
How to delete a file in Win XP ?
#another method:
yourtarget="C:/Documents and Settings/greg/My Documents/targetfile.pdf"
require 'win32ole'
WIN32OLE.new("Scripting.FileSystemObject").deleteFile(yourtarget)
# I didn't address file lock.
--
Posted via http://www.ruby-forum.com/\.
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 pm, Serg Koren <myEmailLi...@comcast.net> wrote:
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
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,
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
--
Luis Lavena
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
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.
Mateusz Winiarski wrote:
deleting in windows explorer works fine in the same account
Yes, it is true. However, if you run your script and forget to close the
file, the unlink/delete/rm fails!
In Windows Explorer deleting always succeeds because your script is --
probably -- not active. (So, all of your files are closed by Ruby
engine, even if you doesn't closed them explicite.)
You cannot delete a file that is already open. You have to close it
before deletion.
WRONG:
f = File.open('jadzia','w+')
File.unlink('jadzia') =====> ERROR
RIGHT:
f = File.open('jadzia','w+')
f.close
File.unlink('jadzia') =====> OK!
--
Posted via http://www.ruby-forum.com/\.
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:
> > 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.
WRONG:
f = File.open('jadzia','w+')
File.unlink('jadzia') =====> ERRORRIGHT:
f = File.open('jadzia','w+')
f.close
File.unlink('jadzia') =====> OK!
EVEN BETTER:
open('jadzia', 'w+') { |file|
# write to the file
} # here ruby auto-closes the file
File.unlink('jadzia') =====> OK!
I like the blockform better, since it prevents me from forgetting
to call close, which i do almost all the time...
Greetz!
Short answer: you can.
Windows don't let you remove files that remain open or captured by
other process. There is also no easy way to access the unlocking API
to release those file handlers.
May I ask what are you trying to do?
What you're expecting that ruby accomplish you can't accomplish even
using Windows Explorer, both will show the same error since this is
happening on a lower level in the OS.
If you desperately need to release that file handler to remove the
file (dunno the reason, use at your own risk), look for Unlocker:
http://ccollomb.free.fr/unlocker/
HTH,
On Jul 10, 7:51 am, MAwiniarski <MAwiniar...@gmail.com> wrote:
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 ??
--
Luis Lavena
maybe the file name contains "\" instead of "/" ?
--
Posted via http://www.ruby-forum.com/.
If you desperately need to release that file handler to remove the
file (dunno the reason, use at your own risk), look for Unlocker:
Or, perhabs unlocker _shows, which_ process/application locks the
file. Maybe, even this helps.
If unlocker does not do the job, you can try mst IsUsedBy:
http://www.mstsoftware.com/de/Produkte/Freeware
But I never used it.
- Axel
> 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 ??
Short answer: you can.
Windows don't let you remove files that remain open or captured by
other process. There is also no easy way to access the unlocking API
to release those file handlers.
I'm trying to delete normal file which I CAN delete with windows
explorer.
And file is not opened by another application. It is simple 0 bytes
file
created earlier as a mock file for application development testing.
On Jul 10, 9:39 am, Luis Lavena <luislav...@gmail.com> wrote:
On Jul 10, 7:51 am, MAwiniarski <MAwiniar...@gmail.com> wrote:
May I ask what are you trying to do?
What you're expecting that ruby accomplish you can't accomplish even
using Windows Explorer, both will show the same error since this is
happening on a lower level in the OS.If you desperately need to release that file handler to remove the
file (dunno the reason, use at your own risk), look for Unlocker:http://ccollomb.free.fr/unlocker/
HTH,
--
Luis Lavena
Ok, you're trying to delete the file from the same process?
If the file was created with this syntax:
f = File.open('foo', 'w')
then you need to close it (f.close)
sometimes that doesn't work, so better if you do the file operations
in a block:
File.open('foo', 'w') do |f|
f.puts "xxx"
end
That will release the file description and let you unlink it.
If, by contrary, you fold the file descriptor, nothing can be done
(use Unlocker to see who is holding the file).
HTH,
On Jul 10, 12:11 pm, MAwiniarski <MAwiniar...@gmail.com> wrote:
On Jul 10, 9:39 am, Luis Lavena <luislav...@gmail.com> wrote:> On Jul 10, 7:51 am, MAwiniarski <MAwiniar...@gmail.com> wrote:
> > 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 ??
> Short answer: you can.
> Windows don't let you remove files that remain open or captured by
> other process. There is also no easy way to access the unlocking API
> to release those file handlers.I'm trying to delete normal file which I CAN delete with windows
explorer.
And file is not opened by another application. It is simple 0 bytes
file
created earlier as a mock file for application development testing.
--
Luis Lavena