From: Peter Bailey Date: 2013-05-08T21:26:06+09:00 Subject: Re: Problem with FileUtils move command. Daniel Stephens wrote in post #1108224: > can you post some of the script? Sure. Here it is. require 'rubygems' require 'fileutils' require 'net/ftp' Dir.chdir("F:/workflows/graphics/asura-non/RCSCR/in") if Dir.glob("*.pdf").length == 0 then exit end pdffile = ARGV[0] ######################## PDF Input Files ####################### #First, check to see if the PDFs are good PDFs. pdfinfo = `alchemy #{pdffile} -x 2>&1` pdfinfo.scan(/Error reading PostScript|Cannot identify file/) do |match| if match File.open("//mako/logs/statusreports/RCSCR.log", "a") { |f| f.print " #{pdffile} is a BAD PDF file and can't be processed\n" } FileUtils.mv(pdffile, "F:/workflows/graphics/asura-non/RCSCR/badfiles") end end puts pdffile FileUtils.mv(pdffile, "F:/workflows/graphics/asura-non/RCSCR/scratch") #Go to the scratch area and process the file. Dir.chdir("F:/workflows/graphics/asura-non/RCSCR/scratch") pages = `pdfinfo #{pdffile}` pages.scan(/^Pages: ([0-9]{1,5})/) do |_| $pagecount = $1 end if $pagecount != "1" puts "\n#{pdffile} is a multi-paged PDF file.\n" pngfile = File.basename(pdffile, ".*") + ".png" tifffile = File.basename(pdffile, ".*") + ".tif" `alchemy #{pdffile} ---n9 -Za2 -Zc1 -Zm2 -Zd 300 300 -o` `alchemy #{pdffile} -t1 -Zc1 -Zd 300 300 -U ---U` else puts "\n#{pdffile} is a single-paged PDF file.\n" pngfile = File.basename(pdffile, ".*") + ".png" tifffile = File.basename(pdffile, ".*") + ".tif" `alchemy #{pdffile} -t1 -Zc1 -Zm1 -Zd 300 300 -o` info = `alchemy #{tifffile} -x` info.scan(/Image size \(inches\): ([0-9\.]{1,5})/) do |_| info = $1 puts info puts info.to_i end if info.to_i < 4 puts "#{pdffile} is less than 4 inches wide" `alchemy #{pdffile} ---n9 -Za2 -Zc1 -Zm2 -Zd 300 300 -o` else puts "#{pdffile} is more than 4 inches wide" `alchemy #{pdffile} ---n9 -Za2 -Zc1 -Zm2 -Zd 300 300 -o` end end #Send to Orca t = Time.now begin `curl -u production:prod --data-binary @#{tifffile} -H "Content-type: application/image" -H "Expect: " http://ps2000-graphics-test.bna.com/image/loader/#{tifffile}` File.open("E:/logs/StatusReports/RCSCR.log", "a") { |f| f.print "Sent to Orca: #{tifffile} at #{t.strftime("%m/%d/%y %H%M %p")}\n" } rescue File.open("E:/logs/StatusReports/RCSCR.log", "a") { |f| f.print "NOT sent to Orca: #{tifffile} at #{t.strftime("%m/%d/%y %H%M %p")}\n" } system("netmailbot -logfile E:/temp/netmailbot.log -appendlog -subject \"RCSCR FILES: #{tifffile} did not go to Orca!\" -to prodadmin@bna.com -fromfriendly \"MAKO Mail Server\" -from pbailey@bna.com -server 10.70.50.52") end begin `curl -u production:prod --data-binary @#{pdffile} -H "Content-type: application/image" -H "Expect: " http://ps2000-graphics-test.bna.com/image/loader/#{pdffile}` File.open("E:/logs/StatusReports/RCSCR.log", "a") { |f| f.print "Sent to Orca: #{pdffile} at #{t.strftime("%m/%d/%y %H%M %p")}\n" } rescue File.open("E:/logs/StatusReports/RCSCR.log", "a") { |f| f.print "NOT sent to Orca: #{pdffile} at #{t.strftime("%m/%d/%y %H%M %p")}\n" } system("netmailbot -logfile E:/temp/netmailbot.log -appendlog -subject \"RCSCR FILES: #{pdffile} did not go to Orca!\" -to prodadmin@bna.com -fromfriendly \"MAKO Mail Server\" -from pbailey@bna.com -server 10.70.50.52") end begin `curl -u production:prod --data-binary @#{pngfile} -H "Content-type: application/image" -H "Expect: " http://ps2000-graphics-test.bna.com/image/loader/#{pngfile}` File.open("E:/logs/StatusReports/RCSCR.log", "a") { |f| f.print "Sent to Orca: #{pngfile} at #{t.strftime("%m/%d/%y %H%M %p")}\n" } rescue File.open("E:/logs/StatusReports/RCSCR.log", "a") { |f| f.print "NOT sent to Orca: #{pngfile} at #{t.strftime("%m/%d/%y %H%M %p")}\n" } system("netmailbot -logfile E:/temp/netmailbot.log -appendlog -subject \"RCSCR FILES: #{pngfile} did not go to Orca!\" -to prodadmin@bna.com -fromfriendly \"MAKO Mail Server\" -from pbailey@bna.com -server 10.70.50.52") end #Send to BWD #PDFs. ftp = Net::FTP.open('genesis.bna.com') ftp.login('pb4072', 'retep1') ftp.chdir('/gateway/bwd/test/normal') ftp.putbinaryfile(pdffile.downcase) File.delete(pdffile) #PNGs. ftp = Net::FTP.open('genesis.bna.com') ftp.login('pb4072', 'retep1') ftp.chdir('/gateway/bwd/test/normal') ftp.putbinaryfile(pngfile.downcase) File.delete(pngfile) #Delete the TIFF files. FileUtils.rm(tifffile) -- Posted via http://www.ruby-forum.com/.