problems with escaped characters in file::stat

Discussion in 'Ruby' started by tigerd, Jul 21, 2006.

  1. tigerd

    tigerd Guest

    Hey.
    I hva got a really mindchrusher problem. I've made a program that
    somewhere goes through a list of files, picked with a tar command, and
    then collects the size and time of every single file/dirs. It goes
    something like this:

    system("tar --totals -cvf /dev/null -C #{@basedir} #{directory} >
    #{@tempfile} 2> /dev/null")
    templist = File.new(tempfile)
    while file = templist.gets
    next if file == nil
    file = file.chop
    if file =~ /.*?\/$/
    stat_d = File::Stat.new(File.join(TEMPDIR, file)) if
    (@mode['static'] == nil)
    stat_d = File::Stat.new("#{@basedir}/#{file}") if
    (@mode['static'] != nil)
    end
    end

    The problem now is that if a file has a special character, tar puts the
    filename like this

    1. /../path/bioligep\345.psd
    this file ruby cannot find, since the name in the unix-world is(its on
    a linux platfom)
    2. /../path/bioligep?.psd

    My question is: Is there anyway I can translate the line no. 1 into
    line no 2? Ive looked at the File.fnmatch but havent really gotten
    anywere

    Greeting, Allan
     
    tigerd, Jul 21, 2006
    #1
    1. Advertising

  2. tigerd

    tigerd Guest

    ps. the ? is acutally a æ in the real world...but unix pukes on it..
     
    tigerd, Jul 21, 2006
    #2
    1. Advertising

  3. On Jul 21, 2006, at 5:00 AM, tigerd wrote:

    > path/bioligep\345.psd


    string_to_pass_to_stat = filename_string.gsub(/\\(\d{3})/){ $1.to_i
    (8).chr }
     
    Logan Capaldo, Jul 21, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    797
  2. Steven T. Hatton
    Replies:
    3
    Views:
    9,746
    Pete Becker
    Jun 2, 2005
  3. Patrick Useldinger

    os.stat('<filename>')[stat.ST_INO] on Windows

    Patrick Useldinger, Feb 27, 2005, in forum: Python
    Replies:
    6
    Views:
    1,212
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Mar 3, 2005
  4. Magesh
    Replies:
    3
    Views:
    462
    Gordon Burditt
    Oct 5, 2007
  5. Rolf Krüger
    Replies:
    2
    Views:
    636
    Ian Collins
    Mar 12, 2008
Loading...

Share This Page