# Failing with Dir.glob results

**URL:** <https://www.ruby-forum.com/t/failing-with-dir-glob-results/63809>\
**Category:** Ruby\
**Created:** [June 19, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/failing-with-dir-glob-results/63809 "2006-06-19T16:11:21Z")\
**Posts on this page:** 6\
**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:** [June 19, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/failing-with-dir-glob-results/63809/1 "2006-06-19T16:11:21Z")

</div>

Hello,  
My script is failing at the following move command, right after the  
capturing of a bunch of files in a directory. My glob is a big one. It’s  
checking against 49 different file prefixes. Is that a problem? All I  
want it to do for now is copy any files that conform to one of those  
prefixes.

Thanks.

* * *

require ‘FileUtils’

…

ps2kfiles =  
Dir.glob("{aacmc7,acm059,acm061,acmc59,acmt59,adc064,adm065,cbncc7,cgmpr,cpslit,cpsmco,edc131,edt131,eeomc7,emgc15,hcc201,hcci01,hct201,hcti01,hla020,hlai20,hlb020,hlbi20,hltc20,hlti20,ierc78,itc101,jsc047,lrc013,lrfl21,lrnm21,lrrc21,lrrc22,lrrc24,lrrc37,lrrc49,lrrc74,lrrmc6,lrrt37,lrt013,mopc68,mopd68,mopec8,mopt68,pgc117,pslc45,psvc45,rtc129,uln007,}\*.pdf")

ps2kfiles.each do |ps2kfile|  
FileUtils.mv ‘#{ps2kfile}’, ‘C:/scripts/ruby/temp/test/indextemp/ps2k/’  
end

---

<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:** [June 19, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/failing-with-dir-glob-results/63809/2 "2006-06-19T17:31:43Z")

</div>

On Jun 19, 2006, at 15:11, Peter B. wrote:

> Hello,  
> My script is failing at the following move command, right after the  
> capturing of a bunch of files in a directory. My glob is a big one.  
> It’s  
> checking against 49 different file prefixes. Is that a problem? All I  
> want it to do for now is copy any files that conform to one of those  
> prefixes.

What’s the nature of the failure? Do you get any sort of error message?

If you reduce the number of prefixes, does that solve the problem?  
For example, does this work:  
Dir.glob("{aacmc7, acm059}\*.pdf")

What about this?  
Dir.glob(“aacmc7\*.pdf”)

Sorry I can’t answer specifically, but answering those questions  
ought to get you at least part of the way to what the real problem is.

matthew smillie.

---

<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:** [June 19, 2006, 6:09pm UTC](https://www.ruby-forum.com/t/failing-with-dir-glob-results/63809/3 "2006-06-19T18:09:19Z")

</div>

Hi,

At Mon, 19 Jun 2006 23:11:44 +0900,  
Peter B. wrote in [ruby-talk:198037]:

> ps2kfiles =  
> Dir.glob("{aacmc7,acm059,acm061,acmc59,acmt59,adc064,adm065,cbncc7,cgmpr,cpslit,cpsmco,edc131,edt131,eeomc7,emgc15,hcc201,hcci01,hct201,hcti01,hla020,hlai20,hlb020,hlbi20,hltc20,hlti20,ierc78,itc101,jsc047,lrc013,lrfl21,lrnm21,lrrc21,lrrc22,lrrc24,lrrc37,lrrc49,lrrc74,lrrmc6,lrrt37,lrt013,mopc68,mopd68,mopec8,mopt68,pgc117,pslc45,psvc45,rtc129,uln007,}\*.pdf")

This globs aacmc7\*.pdf, acm059\*.pdf, … and \*.pdf. So  
prefixed files will be listed twice.

---

<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:** [June 19, 2006, 10:21pm UTC](https://www.ruby-forum.com/t/failing-with-dir-glob-results/63809/4 "2006-06-19T22:21:38Z")

</div>

On 6/19/06, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> require ‘FileUtils’
> 
> …
> 
> ps2kfiles =  
> Dir.glob(“{aacmc7,acm059,acm061,acmc59,acmt59,adc064,adm065,cbncc7,cgmpr,cpslit,cpsmco,edc131,edt131,eeomc7,emgc15,hcc201,hcci01,hct201,hcti01,hla020,hlai20,hlb020,hlbi20,hltc20,hlti20,ierc78,itc101,jsc047,lrc013,lrfl21,lrnm21,lrrc21,lrrc22,lrrc24,lrrc37,lrrc49,lrrc74,lrrmc6,lrrt37,lrt013,mopc68,mopd68,mopec8,mopt68,pgc117,pslc45,psvc45,rtc129,uln007,}\*.pdf”)
> 
> ps2kfiles.each do |ps2kfile|  
> FileUtils.mv ‘#{ps2kfile}’, ‘C:/scripts/ruby/temp/test/indextemp/ps2k/’  
> end

Did you mean to have that last comma at the end of all those prefixes?  
(prefixi? prefixin’? 😉 )

—John

---

<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:** [June 20, 2006, 3:12pm UTC](https://www.ruby-forum.com/t/failing-with-dir-glob-results/63809/5 "2006-06-20T15:12:22Z")

</div>

Matthew S. wrote:

> On Jun 19, 2006, at 15:11, Peter B. wrote:
> 
> > Hello,  
> > My script is failing at the following move command, right after the  
> > capturing of a bunch of files in a directory. My glob is a big one.  
> > It’s  
> > checking against 49 different file prefixes. Is that a problem? All I  
> > want it to do for now is copy any files that conform to one of those  
> > prefixes.
> 
> What’s the nature of the failure? Do you get any sort of error message?
> 
> If you reduce the number of prefixes, does that solve the problem?  
> For example, does this work:  
> Dir.glob("{aacmc7, acm059}\*.pdf")
> 
> What about this?  
> Dir.glob(“aacmc7\*.pdf”)
> 
> Sorry I can’t answer specifically, but answering those questions  
> ought to get you at least part of the way to what the real problem is.
> 
> matthew smillie.

Yes, absolutely. I have no problems when I have far fewer glob choices.  
But, I donâ??t think my problem here is the globbing itself. Thatâ??s what  
Iâ??ve discovered. My error message points to the move command. Iâ??ve since  
corrected and made this file useable by replacing my FileUtils move with  
a simple system move command.

Thank you for your help.

---

<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:** [June 20, 2006, 3:13pm UTC](https://www.ruby-forum.com/t/failing-with-dir-glob-results/63809/6 "2006-06-20T15:13:51Z")

</div>

John G. wrote:

> On 6/19/06, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > require ‘FileUtils’
> > 
> > …
> > 
> > ps2kfiles =  
> > Dir.glob(“{aacmc7,acm059,acm061,acmc59,acmt59,adc064,adm065,cbncc7,cgmpr,cpslit,cpsmco,edc131,edt131,eeomc7,emgc15,hcc201,hcci01,hct201,hcti01,hla020,hlai20,hlb020,hlbi20,hltc20,hlti20,ierc78,itc101,jsc047,lrc013,lrfl21,lrnm21,lrrc21,lrrc22,lrrc24,lrrc37,lrrc49,lrrc74,lrrmc6,lrrt37,lrt013,mopc68,mopd68,mopec8,mopt68,pgc117,pslc45,psvc45,rtc129,uln007,}\*.pdf”)
> > 
> > ps2kfiles.each do |ps2kfile|  
> > FileUtils.mv ‘#{ps2kfile}’, ‘C:/scripts/ruby/temp/test/indextemp/ps2k/’  
> > end
> 
> Did you mean to have that last comma at the end of all those prefixes?  
> (prefixi? prefixin’? 😉 )
> 
> —John

Youâ??re right. I did see that, and, I deleted it. It didn’t change my  
results, though. But, as I told Matthew, it appears my problem here was  
not the glob itself, but the FileUtils move command. I replaced that,  
for now, with a simple system move command, and it works.

Thanks!
