I've read elsewhere that on XP, if you have a filehandle open, the move 
will fail.

My own experience was that using UNC paths worked where Windows-style 
did not.

I am using a UNC path to iterate through the folder structure (to get 
all the text files (i.e. pattern matching against *.txt)), and then I'm 
doing a move and rename all in one, using Windows-style paths.

When my declaration was localdir = ImportDirName+folder, I got the 
permission error.


 ImportDirName = "C:\\Dev\\FKPConversion\\Text\\"
 RenamedDirName = "C:\\Dev\\FKPConversion\\TextProcessed\\"
 ImportUNCName = "\\\\c0151\\Text\\"
 foldercount = 0
 File.open(ImportListName).each { |line|
 folder = line.chomp
 unc = ImportUNCName + folder
 localdir = ImportUNCName+folder
 Dir.chdir(localdir) do
  Dir.glob("*.txt").each { |interest|
    strippedfile = interest.gsub('.txt','')
    src="N:\\#{strippedfile}"
    dest="N:\\#{folder}"
    FileUtils.mv src,dest
  }
  splitfolder=folder.split('\\')
  endfolder=splitfolder[-1]
  puts endfolder
  renamesrc="#{ImportDirName}#{folder}"
  renamedest="#{RenamedDirName}#{endfolder}_#{foldercount}"
  FileUtils.mv renamesrc, renamedest
  foldercount+=1
 end

Hope this helps, Nick.
-- 
Posted via http://www.ruby-forum.com/.