# File.rename failing after a few thousand successes . .

**URL:** <https://www.ruby-forum.com/t/file-rename-failing-after-a-few-thousand-successes/117264>\
**Category:** Ruby\
**Created:** [October 15, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/file-rename-failing-after-a-few-thousand-successes/117264 "2007-10-15T14:21:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [October 15, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/file-rename-failing-after-a-few-thousand-successes/117264/1 "2007-10-15T14:21:35Z")

</div>

Hello,  
With help from this forum, I’ve been successful in parsing through  
directories of thousands of graphics files. I need to determine which  
files are postscript EPS files. Any files that aren’t EPS files I can  
assume are TIFF files. I have to do this because our [unix] publishing  
system doesn’t use file extensions, so, in its image library, all  
graphics files have no extensions. I’m needing to parse through these  
files to get rid of any color files, make them grayscale. Anyway, I have  
a directory now with over 23,000 files in it. I’ve run a script with  
this clause in it.

Dir.glob("\*").each do |file|  
if /%!PS-Adobe/ =~ open(file) {|f| f.gets}  
File.rename(file, file + “.eps”)  
end  
end

It runs just fine and does a rename for 3123 files. But, then, suddenly,  
it fails with a message:

Exception: Permission denied - in

Any ideas?

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [October 15, 2007, 2:51pm UTC](https://www.ruby-forum.com/t/file-rename-failing-after-a-few-thousand-successes/117264/2 "2007-10-15T14:51:01Z")

</div>

-------- Original-Nachricht --------

> Datum: Mon, 15 Oct 2007 21:21:36 +0900  
> Von: Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: File.rename failing after a few thousand successes . . .

> Any ideas?
> 
> ## Thanks, Peter
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Dear Peter,

you don’t have the right to read or to write that particular file,  
maybe because it was created by another user or by root, and now  
you’re running your Ruby script as a normal user.  
On the command line, you can change the rights to read, write and  
execute files, as root, using  
the chmod command.

> **[chmod](https://en.wikipedia.org/wiki/Chmod)**
>
> In Unix and Unix-like operating systems, .mw-parser-output .monospaced{font-family:monospace,monospace}chmod is the command and system call used to change the access permissions and the special mode flags (the setuid, setgid, and sticky flags) of file system objects (files and directories). Collectively these were originally called its modes, and the name chmod was chosen as an abbreviation of change mode.
> A chmod command first appeared in AT&T UNIX version 1, along with the chmod system call.

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [October 15, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/file-rename-failing-after-a-few-thousand-successes/117264/3 "2007-10-15T15:00:59Z")

</div>

You need to get the script to display the name of the file that it  
failed on (unless you simply didn’t show it in your excerpt) and then  
look at the permissions for the file in question.

Also it would be a good idea to catch the exception in your code so that  
you can report the error and then carry on. Also make sure that you do  
not process the any files that you have already processed on a previous  
run by ignoring file names that end in “.eps”.

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [October 15, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/file-rename-failing-after-a-few-thousand-successes/117264/4 "2007-10-15T15:02:03Z")

</div>

Axel E. wrote:

> -------- Original-Nachricht --------
> 
> > Datum: Mon, 15 Oct 2007 21:21:36 +0900  
> > Von: Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > An: removed\_email\_address@domain.invalid  
> > Betreff: File.rename failing after a few thousand successes . . .
> 
> > Any ideas?
> > 
> > ## Thanks, Peter
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> Dear Peter,
> 
> you don’t have the right to read or to write that particular file,  
> maybe because it was created by another user or by root, and now  
> you’re running your Ruby script as a normal user.  
> On the command line, you can change the rights to read, write and  
> execute files, as root, using  
> the chmod command.
> 
> [chmod - Wikipedia](http://en.wikipedia.org/wiki/Chmod)
> 
> Best regards,
> 
> Axel

Thanks, Axel. Well, yes, the original files are on Unix, but, all my  
work is happening on a Windows server. I copy it over via SAMBA. But,  
I’m a network administrator with full rights on the server. Maybe the  
copying via SAMBA pulled over some weird permissions or something. I’ll  
look into this further. Thanks again.

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [October 15, 2007, 4:10pm UTC](https://www.ruby-forum.com/t/file-rename-failing-after-a-few-thousand-successes/117264/5 "2007-10-15T16:10:02Z")

</div>

I’ve had weird stuff happen on NFS before–using a local drive worked.  
GL!

Peter B. wrote:

> Hello,  
> With help from this forum, I’ve been successful in parsing through  
> directories of thousands of graphics files. I need to determine which  
> files are postscript EPS files. Any files that aren’t EPS files I can  
> assume are TIFF files. I have to do this because our [unix] publishing  
> system doesn’t use file extensions, so, in its image library, all  
> graphics files have no extensions. I’m needing to parse through these  
> files to get rid of any color files, make them grayscale. Anyway, I have  
> a directory now with over 23,000 files in it. I’ve run a script with  
> this clause in it.
