2003年12月15日(月)

ファイル名操作

以下備忘録

  • ファイル名からサフィックスを剥がす -> basename(1)
    hatanoX> `basename $a .par`.dat
  • C の中なら basename(3) だけど、こいつは suffix を剥がせない
  • sh script なら変数操作
    kwz_work> ${VAR%.par}.dat

今まで `echo $hoge|sed -e 's/.par/.dat/'` してその場を済ませていたのは秘密だッ

結局こんなコードに

  char *s, *d;
  d =  new char [strlen(argv[1])+4] ;
  if ((s=strrchr(argv[1], '.')) == NULL)
    s=strrchr(argv[1], '\0');

  strncpy(d, argv[1], (size_t)(s-argv[1]));
  strcat(d, ".dat");

一見動いてるけどにゃ〜

こらぼれーてど、うぃず #うにっくす:*.jp
相談に乗ってくれた人たち、どうもでした。

再度ちなむと、 .dat とか .par とか決め打ちになっているのは make で叩きまくる予定だから。

[referer:

Script Error

The script did not produce proper HTTP headers. Please see the error log to see the detail of the errors. Depending on the server configuration, you can also run thisscript under CGIWrap debugging. Usually, either rename or linkthe script temporarily to a file which ends with .cgidextension, or add a AddHandler cgi-script-debug .cgiline to your .htaccess file.

]

あわせて読みたい