File ManagementJ

(cached)
refresh print

ファイル管理




 CindyScriptでファイル操作を行なういくつかの方法があります。しかし、これらのコマンドはHTMLページのアプレットでは動作しないことを注意してください。



データの読み込み



ディレクトリを設定する: setdirectory(<string>)



説明: この演算子は、これ以降のファイルのディレクトリを設定します。ファイルの読み書きをするときは、対象となるディレクトリを設定してから行ないます。設定しない場合はエラーとなります。

例: Windowsでデスクトップにディレクトリを設定する場合、たとえば
   setdirectory(C:¥Documents and Settings\ユーザー名\デスクトップ);
のようにします。デスクトップのディレクトリは、Windowsのバージョンによって異なりますので確かめてください。
Macintoshの場合も同様ですが、 Cinderella をデスクトップに置いてあれば
   setdirectory("../../../../");
でデスクトップを指定できます。Cinderellaがあるのと同じフォルダです。





データの読み込み: load(<string>)



説明: この演算子の引数 はファイル名とします。ディレクトリ名を含んでも構いません。 ファイル名が正しければ、ファイルに含まれる全情報が文字列として返されます。この演算子は tokenize とともに、データを解析するのに有用です。データは setdirectory で指定されたディレクトリから読まれます。

例: ファイル LoadDemo.txt には次のデータが入っているものとします。

abc,gfdg;1,3,5.6,3.141;56,abc,xxx,yyy

次のコードは、データを読み込んで ";" と "," によりトークン化されたリストを作ります。

x=load("LoadTest.txt");
y=tokenize(x,(";",","));
apply(y,println(#));


結果として次のものを出力します。

[abc,gfdg]
[1,3,5.6,3.141]
[56,abc,xxx,yyy]





プログラムコードの読み込み: import(<string>)



説明: この演算子の引数 はファイル名とします。ディレクトリ名を含んでも構いません。ファイル名が正しければ、ファイルの内容は CindyScript のコードとして解析され、実行されます。こうして、あらかじめ定義された関数ライブラリを読み込むことができます。 import 演算子は CindyScript の "Initialization" スロットだけで運用するのがよいでしょう。そうでないと、動作のたびに読み込まれることになります。







ファイルへの書き出し


 Cindy script のスクリプトをファイルへ書き出すこともできます。よく使われるのは次の手順です。

  • 1. setdirectory()関数を用いてディレクトリを指定する。
  • 2. ファイルを開く
  • 3. ファイルに書く
  • 4. ファイルを閉じる

これは次の命令で行ないます。




ファイルを開く: openfile(<string>)



説明: 指定した名前のファイルを開きます。戻り値はprint命令で必要なファイルハンドルです。




ファイルに書いて改行する: println(<file>,<string>)



説明: println(...) と同様ですが、 <file> で指定したファイルに書き出します。




ファイルに書く: print(<file>,<string>)



説明: print(...) と同様ですが <file> で指定したファイルに書き出します。




ファイルを閉じる: closefile(<file>)



説明: ファイルを閉じます。

例: 次の例は、ファイルに書き出す一連の手順を示します。:

setdirectory("../../../../");
f=openfile("myFile");
println(f,"Here are some numbers");
forall(1..15,print(f,#+" ");
println(f,"");
closefile(f);


これにより、次のような内容のファイルが作られます。:

Here are some numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 






HTMLとの連携



Webページを開く: openurl(<string>)



説明: <string>のWebページをブラウザで開きます。



javascriptを呼びだす: javascript(<string>)




説明: 書き出されたアプレットにおいて、ブラウザの Javascript 環境での命令を呼びだします。この命令の内容は <string> に書きます。スタンドアロンのアプリケーションでは何もしません。

例: 次のコードでは、ブラウザ上にポップアップウィンドウを表示してメッセージを出します。

  javascript("alert('Hi from Cinderella!!')");



ネットワーク



シンデレラでの TCP コマンドはほんの簡単なものだけです。しかしネットワークの基本的な機能はあります。インターネット上でデータを送受信することができるはずです。

TCP ポートを開く: openconnection(<string>,<int>)


説明: 第1引数で指定されたサーバーへのTCP接続を行い、第2引数で指定されたポートを開きます。戻り値は、このネットワーク接続へのハンドルです。

TCP へ書きだす: print(<handle>,<string>)


TCPへ書きだす: println(<handle>,<string>)


説明: printprintln 関数は、ファイルだけでなく openconnectionによって作られるネットワークへも書き出しを行ないます。

TCP ポートへの出力と消去: flush(<handle>)


説明: 与えられた接続への出力バッファを消去します。

TCP 接続からの読み込み: readln(<handle>)


説明: 与えられた接続から行を読みます。もしデータがなければ5秒後にタイムアウトします。

TCP 接続を閉じる: closeconnection(<handle>)


説明: 与えられたハンドルの接続を閉じます。


例:次のコードでは、Webサーバを開いて、そこからHTMLコードを読み出します。
x=openconnection("cermat.org",80);
println(x,"GET /");
y="";
while(!isundefined(y),y=readln(x);println(y));
closeconnection(x);



Contributors to this page: Akira Iritani .
Page last modified on Friday 13 of April, 2012 [10:51:18 UTC] by Akira Iritani.

The content on this page is licensed under the terms of the License.


Menu
free viagra samplehentai girlsmature pussymilfseeker cialis samplescam clip movie nude webcammother incest order viagra online cialis ukanime rapeparis hilton phone numbers viagra alternatives cialis forum cialis free samplehot girls in pantiesmonster of cocks discount cialis cilias free viagra samplesfree chat rooms cilia structurefree cartoon sex comics buy cialis order viagrafree adult videosplump girl gallerypantyhose gallerycum on her face cheapest cialisbisexual moviestampa bukakehuge black cock thumbnails buy cialis onlineporn star cialis drugwomen having sex cheap generic viagra alternative to viagra natural viagra cheap viagraoral sexteen webcam strip videosnude spanish girlserotic sex cams movies viagra side effectscartoon adultdisney sex animenude blonde hairygang bang swinger cialis viagrabisexual free moviesgay twinkswebcam chat live xxxyoung teens order cialislatina girls thongscum loversjapanese girl viagra cheapyoung japanese girlsmr chews asian beavergangbang squadshoshone indiansmature wiveslive webcam chat girlsfree ebony viagra on lineasian ladyboysteen boys viagra pillsself bondage techniques cailisincest familyfree ebony cheap cialisgay amateur cialis genericbusty asian viagra onlinemature breasts viagra for women free viagrabig boobies cialis generic viagragloryhole gaylatinas in thongs female viagraindian tits viagra 6 free samplesamateur upskirt viagra alternativefree xxx video cialis online discountgalleries of teen girls cialis dosage cheap generic cialisparis hilton pornopussy cat dollsbrutal sexgay peopleblack milfsno tits discount viagrablonde hairy pussyshemale animefree hardcore moviesmom strips for sonfat titscelebrity legsdouble anal levitra vs cialis cialis tadalafil cialis cheapgay bdsmcelebrities exposed viagra generic alternatives to viagra viagra canadabestialitypink porn stars viagra jokesclips of teen sexchicks suck horse cock online viagrasex with horsespainful analglory holes floridafree american bukkake cialis online buy viagrabig cock cum free cialisteen gay porn cialis side effects herbal viagra best price viagra purchase cialis cialis soft tabs cialis vs viagrafree fat girl webcamfree porn movie clipsoral penis suckingebony hardcore viagra pricepantyhose crossed legs cialis and levitralesbiennesblonde boobs buy viagra online