-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfiles.html
927 lines (797 loc) · 65 KB
/
files.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Files — Ring 1.14 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="System Functions" href="systemfunc.html" />
<link rel="prev" title="Mathematical Functions" href="mathfunc.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html">
<img src="_static/ringdoclogo.jpg" class="logo" alt="Logo"/>
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="ringapps.html">Applications developed in a few hours</a></li>
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringnotepad.html">Using Ring Notepad</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting Started - First Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting_started2.html">Getting Started - Second Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting_started3.html">Getting Started - Third Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="variables.html">Variables</a></li>
<li class="toctree-l1"><a class="reference internal" href="operators.html">Operators</a></li>
<li class="toctree-l1"><a class="reference internal" href="controlstructures.html">Control Structures - First Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="controlstructures2.html">Control Structures - Second Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="controlstructures3.html">Control Structures - Third Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="getinput.html">Getting Input</a></li>
<li class="toctree-l1"><a class="reference internal" href="functions.html">Functions - First Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="functions2.html">Functions - Second Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="functions3.html">Functions - Third Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="programstructure.html">Program Structure</a></li>
<li class="toctree-l1"><a class="reference internal" href="lists.html">Lists</a></li>
<li class="toctree-l1"><a class="reference internal" href="strings.html">Strings</a></li>
<li class="toctree-l1"><a class="reference internal" href="dateandtime.html">Date and Time</a></li>
<li class="toctree-l1"><a class="reference internal" href="checkandconvert.html">Check Data Type and Conversion</a></li>
<li class="toctree-l1"><a class="reference internal" href="mathfunc.html">Mathematical Functions</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Files</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#read-function">Read() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#write-function">Write() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#dir-function">Dir() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#rename-function">Rename() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#remove-function">Remove() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fopen-function">Fopen() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fclose-function">Fclose() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fflush-function">Fflush() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#freopen-function">Freopen() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#tempfile-function">Tempfile() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#tempname-function">Tempname() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fseek-function">Fseek() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#ftell-function">Ftell() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#rewind-function">Rewind() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fgetpos-function">Fgetpos() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fsetpos-function">Fsetpos() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#clearerr-function">Clearerr() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#feof-function">Feof() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#ferror-function">Ferror() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#perror-function">Perror() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fgetc-function">Fgetc() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fgets-function">Fgets() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fputc-function">Fputc() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fputs-function">Fputs() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#ungetc-function">Ungetc() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fread-function">Fread() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fwrite-function">Fwrite() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#fexists-function">Fexists() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#direxists-function">Direxists() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#getpathtype-function">Getpathtype() Function</a></li>
<li class="toctree-l2"><a class="reference internal" href="#example">Example</a></li>
<li class="toctree-l2"><a class="reference internal" href="#numbers-and-bytes">Numbers and Bytes</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="systemfunc.html">System Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="evaldebug.html">Eval() and Debugging</a></li>
<li class="toctree-l1"><a class="reference internal" href="demo.html">Demo Programs</a></li>
<li class="toctree-l1"><a class="reference internal" href="odbc.html">ODBC Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="mysql.html">MySQL Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="sqlite.html">SQLite Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="postgresql.html">PostgreSQL Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="secfunc.html">Security and Internet Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="oop.html">Object Oriented Programming (OOP)</a></li>
<li class="toctree-l1"><a class="reference internal" href="fp.html">Functional Programming (FP)</a></li>
<li class="toctree-l1"><a class="reference internal" href="metaprog.html">Reflection and Meta-programming</a></li>
<li class="toctree-l1"><a class="reference internal" href="declarative.html">Declarative Programming using Nested Structures</a></li>
<li class="toctree-l1"><a class="reference internal" href="natural.html">Natural language programming</a></li>
<li class="toctree-l1"><a class="reference internal" href="naturallibrary.html">Using the Natural Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="scope.html">Scope Rules for Variables and Attributes</a></li>
<li class="toctree-l1"><a class="reference internal" href="scope2.html">Scope Rules for Functions and Methods</a></li>
<li class="toctree-l1"><a class="reference internal" href="syntaxflexibility.html">Syntax Flexibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="typehints.html">The Type Hints Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="debug.html">The Trace Library and the Interactive Debugger</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringemb.html">Embedding Ring Language in Ring Programs</a></li>
<li class="toctree-l1"><a class="reference internal" href="stdlib.html">Stdlib Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="stdlibclasses.html">Stdlib Classes</a></li>
<li class="toctree-l1"><a class="reference internal" href="qt.html">Desktop, WebAssembly and Mobile development using RingQt</a></li>
<li class="toctree-l1"><a class="reference internal" href="formdesigner.html">Using the Form Designer</a></li>
<li class="toctree-l1"><a class="reference internal" href="qt3d.html">Graphics Programming using RingQt3D</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringqtobjects.html">Objects Library for RingQt Application</a></li>
<li class="toctree-l1"><a class="reference internal" href="multilanguage.html">Multi-language Applications</a></li>
<li class="toctree-l1"><a class="reference internal" href="qtmobile.html">Building RingQt Applications for Mobile</a></li>
<li class="toctree-l1"><a class="reference internal" href="qtwebassembly.html">Building RingQt Applications for WebAssembly</a></li>
<li class="toctree-l1"><a class="reference internal" href="web.html">Web Development (CGI Library)</a></li>
<li class="toctree-l1"><a class="reference internal" href="deployincloud.html">Deploying Web Applications in the Cloud</a></li>
<li class="toctree-l1"><a class="reference internal" href="allegro.html">Graphics and 2D Games programming using RingAllegro</a></li>
<li class="toctree-l1"><a class="reference internal" href="gameengine.html">Demo Project - Game Engine for 2D Games</a></li>
<li class="toctree-l1"><a class="reference internal" href="gameengineandorid.html">Building Games For Android</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringraylib.html">Developing Games using RingRayLib</a></li>
<li class="toctree-l1"><a class="reference internal" href="usingopengl.html">Using RingOpenGL and RingFreeGLUT for 3D Graphics</a></li>
<li class="toctree-l1"><a class="reference internal" href="usingopengl2.html">Using RingOpenGL and RingAllegro for 3D Graphics</a></li>
<li class="toctree-l1"><a class="reference internal" href="goldmagic800.html">Demo Project - The Gold Magic 800 Game</a></li>
<li class="toctree-l1"><a class="reference internal" href="tilengine.html">Using RingTilengine</a></li>
<li class="toctree-l1"><a class="reference internal" href="performancetips.html">Performance Tips</a></li>
<li class="toctree-l1"><a class="reference internal" href="compiler.html">Command Line Options</a></li>
<li class="toctree-l1"><a class="reference internal" href="distribute.html">Distributing Ring Applications (Manual)</a></li>
<li class="toctree-l1"><a class="reference internal" href="distribute_ring2exe.html">Distributing Ring Applications using Ring2EXE</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringpm.html">The Ring Package Manager (RingPM)</a></li>
<li class="toctree-l1"><a class="reference internal" href="zerolib.html">ZeroLib Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="foxringfuncsdoc.html">FoxRing Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="bignumber.html">BigNumber Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="libcurl.html">Using RingLibCurl</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringlibcurlfuncsdoc.html">RingLibCurl Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="socket.html">Using RingSockets</a></li>
<li class="toctree-l1"><a class="reference internal" href="threads.html">Using RingThreads</a></li>
<li class="toctree-l1"><a class="reference internal" href="libui.html">Using RingLibui</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringzip.html">Using RingZip</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringlibzipfuncsdoc.html">RingLibZip Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringmurmurhashfuncsdoc.html">RingMurmurHash Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringconsolecolorsfuncsdoc.html">RingConsoleColors Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringallegrofuncsdoc.html">RingAllegro Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="libsdl.html">Using RingLibSDL</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringlibsdlfuncsdoc.html">RingLibSDL Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="libuv.html">Using Ringlibuv</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringlibuvfuncsdoc.html">RingLibuv Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringfreeglutfuncsdoc.html">RingFreeGLUT Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringstbimage.html">RingStbImage Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringopengl32funcsdoc.html">RingOpenGL (OpenGL 3.2) Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="qtclassesdoc.html">RingQt Classes and Methods Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="lowlevel.html">Low Level Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="extension_tutorial.html">Tutorial: Ring Extensions in C/C++</a></li>
<li class="toctree-l1"><a class="reference internal" href="extension.html">Extension using the C/C++ languages</a></li>
<li class="toctree-l1"><a class="reference internal" href="embedding.html">Embedding Ring Language in C/C++ Programs</a></li>
<li class="toctree-l1"><a class="reference internal" href="codegenerator.html">Code Generator for wrapping C/C++ Libraries</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringbeep.html">Create your first extension using the Code Generator</a></li>
<li class="toctree-l1"><a class="reference internal" href="languagedesign.html">Release Notes: Version 1.0</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew.html">Release Notes: Version 1.1</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew2.html">Release Notes: Version 1.2</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew3.html">Release Notes: Version 1.3</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew4.html">Release Notes: Version 1.4</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew5.html">Release Notes: Version 1.5</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew6.html">Release Notes: Version 1.6</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew7.html">Release Notes: Version 1.7</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew8.html">Release Notes: Version 1.8</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew9.html">Release Notes: Version 1.9</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew10.html">Release Notes: Version 1.10</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew11.html">Release Notes: Version 1.11</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew12.html">Release Notes: Version 1.12</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew13.html">Release Notes: Version 1.13</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew14.html">Release Notes: Version 1.14</a></li>
<li class="toctree-l1"><a class="reference internal" href="codeeditors.html">Using Other Code Editors</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions (FAQ)</a></li>
<li class="toctree-l1"><a class="reference internal" href="sourcecode.html">How to Compile Ring From Source Code?</a></li>
<li class="toctree-l1"><a class="reference internal" href="contribute.html">How to contribute?</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference.html">Language Specification</a></li>
<li class="toctree-l1"><a class="reference internal" href="resources.html">Resources</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Ring</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home"></a> »</li>
<li>Files</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="files">
<span id="index-0"></span><h1>Files<a class="headerlink" href="#files" title="Permalink to this headline">¶</a></h1>
<p>In this chapter we are going to learn about files functions.</p>
<ul class="simple">
<li><p>Read()</p></li>
<li><p>Write()</p></li>
<li><p>Dir()</p></li>
<li><p>Rename()</p></li>
<li><p>Remove()</p></li>
<li><p>fopen()</p></li>
<li><p>fclose()</p></li>
<li><p>fflush()</p></li>
<li><p>freopen()</p></li>
<li><p>tempfile()</p></li>
<li><p>tempname()</p></li>
<li><p>fseek()</p></li>
<li><p>ftell()</p></li>
<li><p>rewind()</p></li>
<li><p>fgetpos()</p></li>
<li><p>fsetpos()</p></li>
<li><p>clearerr()</p></li>
<li><p>feof()</p></li>
<li><p>ferror()</p></li>
<li><p>perror()</p></li>
<li><p>fgetc()</p></li>
<li><p>fgets()</p></li>
<li><p>fputc()</p></li>
<li><p>fputs()</p></li>
<li><p>ungetc()</p></li>
<li><p>fread()</p></li>
<li><p>fwrite()</p></li>
<li><p>fexists()</p></li>
<li><p>direxists()</p></li>
<li><p>getpathtype()</p></li>
<li><p>Numbers and Bytes</p></li>
</ul>
<div class="section" id="read-function">
<span id="index-1"></span><h2>Read() Function<a class="headerlink" href="#read-function" title="Permalink to this headline">¶</a></h2>
<p>We can read the file content using the Read() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Read</span><span class="p">(</span><span class="n">cFileName</span><span class="p">)</span> <span class="o">---></span> <span class="kt">String</span> <span class="n">contains</span> <span class="n">the</span> <span class="n">file</span> <span class="n">content</span>
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="n">read</span><span class="p">(</span><span class="s">"myfile.txt"</span><span class="p">)</span>
</pre></div>
</div>
<p>The read function can read binary files too</p>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="n">read</span><span class="p">(</span><span class="s">"myapp.exe"</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="write-function">
<span id="index-2"></span><h2>Write() Function<a class="headerlink" href="#write-function" title="Permalink to this headline">¶</a></h2>
<p>We can write string to file using the Write() function</p>
<p>The write function can write binary data to binary files.</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Write</span><span class="p">(</span><span class="n">cFileName</span><span class="p">,</span><span class="n">cString</span><span class="p">)</span> <span class="c"># write string cString to file cFileName</span>
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="c"># copy file</span>
<span class="n">cFile</span> <span class="o">=</span> <span class="n">read</span><span class="p">(</span><span class="s">"ring.exe"</span><span class="p">)</span>
<span class="n">write</span><span class="p">(</span><span class="s">"ring2.exe"</span><span class="p">,</span><span class="n">cFile</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="dir-function">
<span id="index-3"></span><h2>Dir() Function<a class="headerlink" href="#dir-function" title="Permalink to this headline">¶</a></h2>
<p>We can get the folder contents (files & sub folders) using the Dir() function.</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Dir</span><span class="p">(</span><span class="n">cFolderPath</span><span class="p">)</span> <span class="o">---></span> <span class="kt">List</span> <span class="n">contains</span> <span class="n">files</span> <span class="o">&</span> <span class="n">sub</span> <span class="n">folders</span><span class="p">.</span>
</pre></div>
</div>
<p>This function returns a list and each list item is a list of two items</p>
<ul class="simple">
<li><p>File/sub folder name</p></li>
<li><p>Type (0 = File , 1 = Folder/Directory)</p></li>
</ul>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="s">"Testing DIR() "</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">mylist</span> <span class="o">=</span> <span class="n">dir</span><span class="p">(</span><span class="s">"C:\myfolder"</span><span class="p">)</span>
<span class="k">for</span> <span class="n">x</span> <span class="k">in</span> <span class="n">mylist</span>
<span class="k">if</span> <span class="n">x</span><span class="o">[</span><span class="mi">2</span><span class="o">]</span>
<span class="k">see</span> <span class="s">"Directory : "</span> <span class="o">+</span> <span class="n">x</span><span class="o">[</span><span class="mi">1</span><span class="o">]</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">else</span>
<span class="k">see</span> <span class="s">"File : "</span> <span class="o">+</span> <span class="n">x</span><span class="o">[</span><span class="mi">1</span><span class="o">]</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">ok</span>
<span class="k">next</span>
<span class="k">see</span> <span class="s">"Files count : "</span> <span class="o">+</span> <span class="n">len</span><span class="p">(</span><span class="n">mylist</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="rename-function">
<span id="index-4"></span><h2>Rename() Function<a class="headerlink" href="#rename-function" title="Permalink to this headline">¶</a></h2>
<p>We can rename files using the Rename() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Rename</span><span class="p">(</span><span class="n">cOldFileName</span><span class="p">,</span><span class="n">cNewFileName</span><span class="p">)</span> <span class="o">---></span> <span class="n">Number</span> <span class="p">(</span> <span class="n">Status</span><span class="p">:</span> <span class="n">Success</span> <span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="p">,</span> <span class="n">Error</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">)</span>
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">rename</span><span class="p">(</span><span class="s">"file.txt"</span><span class="p">,</span><span class="s">"help.txt"</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="remove-function">
<span id="index-5"></span><h2>Remove() Function<a class="headerlink" href="#remove-function" title="Permalink to this headline">¶</a></h2>
<p>We can delete a file using the Remove() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Remove</span><span class="p">(</span><span class="n">cFileName</span><span class="p">)</span>
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">remove</span><span class="p">(</span><span class="s">"test.txt"</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="fopen-function">
<span id="index-6"></span><h2>Fopen() Function<a class="headerlink" href="#fopen-function" title="Permalink to this headline">¶</a></h2>
<p>We can open a file using the Fopen() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fopen</span><span class="p">(</span><span class="n">cFileName</span><span class="p">,</span><span class="n">cMode</span><span class="p">)</span> <span class="o">---></span> <span class="n">File</span> <span class="n">Handle</span>
</pre></div>
</div>
<table class="docutils align-default">
<colgroup>
<col style="width: 11%" />
<col style="width: 89%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Mode</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“r”</p></td>
<td><p>Reading (The file must exist)</p></td>
</tr>
<tr class="row-odd"><td><p>“w”</p></td>
<td><p>Writing (create empty file / overwrite)</p></td>
</tr>
<tr class="row-even"><td><p>“a”</p></td>
<td><p>Appends (create file if it doesn’t exist)</p></td>
</tr>
<tr class="row-odd"><td><p>“r+”</p></td>
<td><p>update (reading/writing)</p></td>
</tr>
<tr class="row-even"><td><p>“w+”</p></td>
<td><p>Create empty file (reading/writing)</p></td>
</tr>
<tr class="row-odd"><td><p>“a+”</p></td>
<td><p>reading & appending</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="fclose-function">
<span id="index-7"></span><h2>Fclose() Function<a class="headerlink" href="#fclose-function" title="Permalink to this headline">¶</a></h2>
<p>When we open a file using fopen() function, we can close it
using the Fclose() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fclose</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="fflush-function">
<span id="index-8"></span><h2>Fflush() Function<a class="headerlink" href="#fflush-function" title="Permalink to this headline">¶</a></h2>
<p>We can flushes the output buffer of a stream using the Fflush() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fflush</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="freopen-function">
<span id="index-9"></span><h2>Freopen() Function<a class="headerlink" href="#freopen-function" title="Permalink to this headline">¶</a></h2>
<p>We can open another file using the same file handle and at the same time close
the old file</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Freopen</span><span class="p">(</span><span class="n">cFileName</span><span class="p">,</span><span class="n">cMode</span><span class="p">,</span><span class="n">file</span> <span class="n">handle</span><span class="p">)</span> <span class="o">---></span> <span class="n">file</span> <span class="n">handle</span>
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">freopen</span><span class="p">(</span><span class="s">"myprogoutput.txt"</span><span class="p">,</span><span class="s">"w+"</span><span class="p">,</span><span class="n">stdout</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"welcome"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">for</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">to</span> <span class="mi">10</span>
<span class="k">see</span> <span class="n">x</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">next</span>
<span class="o">/*</span>
<span class="o">**</span> <span class="n">Read</span> <span class="p">:</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">en</span><span class="p">.</span><span class="n">wikipedia</span><span class="p">.</span><span class="n">org</span><span class="o">/</span><span class="n">wiki</span><span class="o">/</span><span class="n">Device_file</span><span class="c">#Device_files</span>
<span class="o">**</span> <span class="n">The</span> <span class="k">next</span> <span class="n">code</span> <span class="n">is</span> <span class="ow">not</span> <span class="n">portable</span><span class="p">,</span> <span class="n">we</span> <span class="n">can</span> <span class="n">use</span> <span class="n">iswindows</span><span class="p">()</span> <span class="n">before</span>
<span class="o">**</span> <span class="n">using</span> <span class="n">it</span> <span class="ow">and</span> <span class="n">we</span> <span class="n">can</span> <span class="n">write</span> <span class="n">special</span> <span class="n">code</span> <span class="k">for</span> <span class="n">each</span> <span class="n">operating</span> <span class="n">system</span><span class="p">.</span>
<span class="o">*/</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"CON"</span><span class="p">,</span><span class="s">"w"</span><span class="p">,</span><span class="n">stdout</span><span class="p">)</span> <span class="c"># For Microsoft Windows</span>
<span class="k">see</span> <span class="s">"Done"</span> <span class="o">+</span> <span class="n">nl</span> <span class="c"># print to stdout again</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="c"># Output to stdout</span>
<span class="k">Done</span>
<span class="c"># Output to file : myprogoutput.txt</span>
<span class="n">welcome</span>
<span class="mi">1</span>
<span class="mi">2</span>
<span class="mi">3</span>
<span class="mi">4</span>
<span class="mi">5</span>
<span class="mi">6</span>
<span class="mi">7</span>
<span class="mi">8</span>
<span class="mi">9</span>
<span class="mi">10</span>
</pre></div>
</div>
</div>
<div class="section" id="tempfile-function">
<span id="index-10"></span><h2>Tempfile() Function<a class="headerlink" href="#tempfile-function" title="Permalink to this headline">¶</a></h2>
<p>The function Tempfile() creates a temp. file (binary).</p>
<p>The file will be deleted automatically when the stream is closed</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">TempFile</span><span class="p">()</span> <span class="o">---></span> <span class="n">file</span> <span class="n">handle</span>
</pre></div>
</div>
</div>
<div class="section" id="tempname-function">
<span id="index-11"></span><h2>Tempname() Function<a class="headerlink" href="#tempname-function" title="Permalink to this headline">¶</a></h2>
<p>We can generate temp. file name using the Tempname() function</p>
<p>The generated name will be different from the name of any existing file</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Tempname</span><span class="p">()</span> <span class="o">---></span> <span class="n">generated</span> <span class="n">file</span> <span class="n">name</span> <span class="n">as</span> <span class="kt">string</span>
</pre></div>
</div>
</div>
<div class="section" id="fseek-function">
<span id="index-12"></span><h2>Fseek() Function<a class="headerlink" href="#fseek-function" title="Permalink to this headline">¶</a></h2>
<p>We can set the file position of the stream using the Fseek() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fseek</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">,</span> <span class="n">nOffset</span><span class="p">,</span> <span class="n">nWhence</span><span class="p">)</span> <span class="o">---></span> <span class="n">zero</span> <span class="k">if</span> <span class="n">successful</span>
</pre></div>
</div>
<p>The next table presents the nWhence values</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 14%" />
<col style="width: 86%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Value</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0</p></td>
<td><p>Beginning of file</p></td>
</tr>
<tr class="row-odd"><td><p>1</p></td>
<td><p>Current position</p></td>
</tr>
<tr class="row-even"><td><p>2</p></td>
<td><p>End of file</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="ftell-function">
<span id="index-13"></span><h2>Ftell() Function<a class="headerlink" href="#ftell-function" title="Permalink to this headline">¶</a></h2>
<p>We can know the current file position of a stream using the Ftell() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Ftell</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">)</span> <span class="o">---></span> <span class="n">file</span> <span class="n">position</span> <span class="n">as</span> <span class="n">number</span>
</pre></div>
</div>
</div>
<div class="section" id="rewind-function">
<span id="index-14"></span><h2>Rewind() Function<a class="headerlink" href="#rewind-function" title="Permalink to this headline">¶</a></h2>
<p>We can set the file position to the beginning of the file using the Rewind() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Rewind</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="fgetpos-function">
<span id="index-15"></span><h2>Fgetpos() Function<a class="headerlink" href="#fgetpos-function" title="Permalink to this headline">¶</a></h2>
<p>We can get handle to the current file position using the Fgetpos() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fgetpos</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">)</span> <span class="o">---></span> <span class="n">position</span> <span class="n">handle</span>
</pre></div>
</div>
</div>
<div class="section" id="fsetpos-function">
<span id="index-16"></span><h2>Fsetpos() Function<a class="headerlink" href="#fsetpos-function" title="Permalink to this headline">¶</a></h2>
<p>We can set the current file position using the Fsetpos() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fsetpos</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">,</span><span class="n">position</span> <span class="n">handle</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="clearerr-function">
<span id="index-17"></span><h2>Clearerr() Function<a class="headerlink" href="#clearerr-function" title="Permalink to this headline">¶</a></h2>
<p>We can clear the EOF error and the error indicators of a stream using the clearerr()
function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Clearerr</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="feof-function">
<span id="index-18"></span><h2>Feof() Function<a class="headerlink" href="#feof-function" title="Permalink to this headline">¶</a></h2>
<p>We can test the end-of-file indicator using the Feof() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Feof</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">)</span> <span class="o">---></span> <span class="n">returns</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">EOF</span> <span class="ow">and</span> <span class="mi">0</span> <span class="k">if</span> <span class="ow">not</span>
</pre></div>
</div>
</div>
<div class="section" id="ferror-function">
<span id="index-19"></span><h2>Ferror() Function<a class="headerlink" href="#ferror-function" title="Permalink to this headline">¶</a></h2>
<p>We can test the error indicator of a given stream using the Ferror() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Ferror</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">)</span> <span class="o">---></span> <span class="n">returns</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">error</span> <span class="ow">and</span> <span class="mi">0</span> <span class="k">if</span> <span class="ow">not</span>
</pre></div>
</div>
</div>
<div class="section" id="perror-function">
<span id="index-20"></span><h2>Perror() Function<a class="headerlink" href="#perror-function" title="Permalink to this headline">¶</a></h2>
<p>We can print error message to the stderr using the Perror() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Perror</span><span class="p">(</span><span class="n">cErrorMessage</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="fgetc-function">
<span id="index-21"></span><h2>Fgetc() Function<a class="headerlink" href="#fgetc-function" title="Permalink to this headline">¶</a></h2>
<p>We can get the next character from the stream using the Fgetc() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fgetc</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">)</span> <span class="o">---></span> <span class="n">returns</span> <span class="n">character</span> <span class="ow">or</span> <span class="n">EOF</span>
</pre></div>
</div>
</div>
<div class="section" id="fgets-function">
<span id="index-22"></span><h2>Fgets() Function<a class="headerlink" href="#fgets-function" title="Permalink to this headline">¶</a></h2>
<p>We can read new line from the stream using the Fgets() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fgets</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">,</span><span class="n">nSize</span><span class="p">)</span> <span class="o">---></span> <span class="kt">string</span>
</pre></div>
</div>
<p>The function stop when nSize characters are read, new line character is read or EOF.</p>
</div>
<div class="section" id="fputc-function">
<span id="index-23"></span><h2>Fputc() Function<a class="headerlink" href="#fputc-function" title="Permalink to this headline">¶</a></h2>
<p>We can write a character to the stream using the Fputc() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fputc</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">,</span><span class="n">cChar</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="fputs-function">
<span id="index-24"></span><h2>Fputs() Function<a class="headerlink" href="#fputs-function" title="Permalink to this headline">¶</a></h2>
<p>We can write a string to the stream using the Fputs() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fputs</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">,</span><span class="n">cString</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="ungetc-function">
<span id="index-25"></span><h2>Ungetc() Function<a class="headerlink" href="#ungetc-function" title="Permalink to this headline">¶</a></h2>
<p>We can push a character to the stream using the Ungetc() function</p>
<p>The character will be available for the next read</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Ungetc</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">,</span><span class="n">character</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="fread-function">
<span id="index-26"></span><h2>Fread() Function<a class="headerlink" href="#fread-function" title="Permalink to this headline">¶</a></h2>
<p>We can read data from a stream using the Fread() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fread</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">,</span><span class="n">nSize</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="fwrite-function">
<span id="index-27"></span><h2>Fwrite() Function<a class="headerlink" href="#fwrite-function" title="Permalink to this headline">¶</a></h2>
<p>We can write data to a stream using the Fwrite() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fwrite</span><span class="p">(</span><span class="n">file</span> <span class="n">handle</span><span class="p">,</span><span class="n">cString</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="fexists-function">
<span id="index-28"></span><h2>Fexists() Function<a class="headerlink" href="#fexists-function" title="Permalink to this headline">¶</a></h2>
<p>We can check if a file exists using the Fexists() function</p>
<p>Syntax:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Fexists</span><span class="p">(</span><span class="n">cFileName</span><span class="p">)</span> <span class="o">---></span> <span class="n">returns</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">the</span> <span class="n">file</span> <span class="n">exists</span>
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="n">fexists</span><span class="p">(</span><span class="s">"b:\mahmoud</span><span class="se">\a</span><span class="s">pps</span><span class="se">\r</span><span class="s">ing</span><span class="se">\r</span><span class="s">ing.exe"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span>
<span class="n">fexists</span><span class="p">(</span><span class="s">"b:\mahmoud</span><span class="se">\a</span><span class="s">pps</span><span class="se">\r</span><span class="s">ing</span><span class="se">\r</span><span class="s">ing2.exe"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="mi">1</span>
<span class="mi">0</span>
</pre></div>
</div>
</div>
<div class="section" id="direxists-function">
<span id="index-29"></span><h2>Direxists() Function<a class="headerlink" href="#direxists-function" title="Permalink to this headline">¶</a></h2>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Direxists(cDirPath) ---> returns 1 if the directory exists
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="o">?</span> <span class="n">direxists</span><span class="p">(</span><span class="s">"b:</span><span class="se">\r</span><span class="s">ing"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span>
<span class="n">direxists</span><span class="p">(</span><span class="s">"b:</span><span class="se">\r</span><span class="s">ing</span><span class="se">\b</span><span class="s">in2"</span><span class="p">)</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>1
0
</pre></div>
</div>
</div>
<div class="section" id="getpathtype-function">
<span id="index-30"></span><h2>Getpathtype() Function<a class="headerlink" href="#getpathtype-function" title="Permalink to this headline">¶</a></h2>
<p>We can get the type a given path (file or directory) using the Getpathtype() function</p>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Getpathtype(cPath) ---> 0 if the path doesn't exists
1 if it corresponds to existing file
2 if it corresponds to existing directory
-1 if the path exists but has
an unknown type (e.g. a pipe)
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="o">?</span> <span class="n">Getpathtype</span><span class="p">(</span><span class="s">"b:</span><span class="se">\r</span><span class="s">ing</span><span class="se">\b</span><span class="s">in</span><span class="se">\r</span><span class="s">ing.exe"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span>
<span class="n">Getpathtype</span><span class="p">(</span><span class="s">"b:</span><span class="se">\r</span><span class="s">ing"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span>
<span class="n">Getpathtype</span><span class="p">(</span><span class="s">"b:</span><span class="se">\r</span><span class="s">ing</span><span class="se">\b</span><span class="s">in2"</span><span class="p">)</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>1
2
0
</pre></div>
</div>
</div>
<div class="section" id="example">
<span id="index-31"></span><h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<p>The next program test some of the file functions</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">See</span> <span class="s">"testing file functions"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">See</span> <span class="s">"open file"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">fp</span> <span class="o">=</span> <span class="n">fopen</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../tests/scripts/s65.ring"</span><span class="p">,</span><span class="s">"r"</span><span class="p">)</span>
<span class="k">See</span> <span class="s">"reopen"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">fp</span> <span class="o">=</span> <span class="n">freopen</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../tests/scripts/s78.ring"</span><span class="p">,</span><span class="s">"r"</span><span class="p">,</span><span class="n">fp</span><span class="p">)</span>
<span class="k">See</span> <span class="s">"close file"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"temp file"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">fp</span> <span class="o">=</span> <span class="n">tempfile</span><span class="p">()</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"temp name"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">see</span> <span class="n">tempname</span><span class="p">()</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">remove</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../tests/scripts/mytest2.txt"</span><span class="p">)</span>
<span class="n">write</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../tests/scripts/tests1.txt"</span><span class="p">,</span><span class="s">"hello"</span><span class="p">)</span>
<span class="n">rename</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../tests/scripts/test1.txt"</span><span class="p">,</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span>
<span class="s">"../tests/scripts/mytests2.txt"</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"print file"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">fp</span> <span class="o">=</span> <span class="n">fopen</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../samples/fromdoc/filefuncs.ring"</span><span class="p">,</span><span class="s">"r"</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">fgetc</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
<span class="k">while</span> <span class="n">isstring</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
<span class="k">see</span> <span class="n">r</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">fgetc</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
<span class="k">end</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
<span class="k">see</span> <span class="n">nl</span><span class="o">+</span><span class="s">"print line from the file"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">fp</span> <span class="o">=</span> <span class="n">fopen</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../samples/fromdoc/filefuncs.ring"</span><span class="p">,</span><span class="s">"r"</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">fgets</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="mi">33</span><span class="p">)</span>
<span class="k">see</span> <span class="n">r</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
<span class="n">fp</span> <span class="o">=</span> <span class="n">fopen</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../tests/scripts/test78.txt"</span><span class="p">,</span><span class="s">"w+"</span><span class="p">)</span>
<span class="n">fseek</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span> <span class="c"># goto end of file</span>
<span class="n">fputc</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="s">"t"</span><span class="p">)</span>
<span class="n">fputc</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="s">"e"</span><span class="p">)</span>
<span class="n">fputc</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="s">"s"</span><span class="p">)</span>
<span class="n">fputc</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="s">"t"</span><span class="p">)</span>
<span class="n">fputs</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="s">"tests2"</span><span class="p">)</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"print file"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">see</span> <span class="n">read</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../tests/scripts/test78.txt"</span><span class="p">)</span>
<span class="n">fp</span> <span class="o">=</span> <span class="n">fopen</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../tests/scripts/test78.txt"</span><span class="p">,</span><span class="s">"r"</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"testing ungetc() "</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">for</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">to</span> <span class="mi">3</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">fgetc</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
<span class="k">see</span> <span class="n">r</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">ungetc</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="n">r</span><span class="p">)</span>
<span class="k">next</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"testing fread() "</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">fp</span> <span class="o">=</span> <span class="n">fopen</span><span class="p">(</span><span class="n">exefilename</span><span class="p">(),</span><span class="s">"rb"</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">fread</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="mi">100</span><span class="p">)</span>
<span class="k">see</span> <span class="n">r</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"testing fwrite() "</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">fp</span> <span class="o">=</span> <span class="n">fopen</span><span class="p">(</span><span class="n">exefolder</span><span class="p">()</span> <span class="o">+</span> <span class="s">"../tests/scripts/test1.txt"</span><span class="p">,</span><span class="s">"wb"</span><span class="p">)</span>
<span class="n">fwrite</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="n">r</span><span class="p">)</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
</pre></div>
</div>
<p>The next example print part of the content of a binary file</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="s">"Testing: fread()"</span> <span class="o">+</span><span class="s">" FileName: "</span><span class="o">+</span> <span class="n">exefilename</span><span class="p">()</span> <span class="o">+</span><span class="n">nl</span> <span class="o">+</span><span class="n">nl</span>
<span class="n">fp</span> <span class="o">=</span> <span class="n">fopen</span><span class="p">(</span><span class="n">exefilename</span><span class="p">(),</span><span class="s">"rb"</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">fread</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span><span class="mi">800</span><span class="p">)</span>
<span class="k">for</span> <span class="n">n</span> <span class="o">=</span><span class="mi">1</span> <span class="k">to</span> <span class="n">len</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
<span class="k">if</span> <span class="n">isprint</span><span class="p">(</span><span class="n">substr</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="k">see</span> <span class="n">substr</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">else</span>
<span class="k">see</span> <span class="s">"."</span>
<span class="k">ok</span>
<span class="sd">### 80 char per line</span>
<span class="k">if</span> <span class="n">n</span> <span class="o">%</span> <span class="mi">80</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">see</span> <span class="n">nl</span>
<span class="k">ok</span>
<span class="k">next</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="numbers-and-bytes">
<span id="index-32"></span><h2>Numbers and Bytes<a class="headerlink" href="#numbers-and-bytes" title="Permalink to this headline">¶</a></h2>
<p>The next functions to convert between Numbers and Bytes.</p>
<ul class="simple">
<li><p>Int2Bytes()</p></li>
<li><p>Float2Bytes()</p></li>
<li><p>Double2Bytes()</p></li>
<li><p>Bytes2Int()</p></li>
<li><p>Bytes2Float()</p></li>
<li><p>Bytes2Double()</p></li>
</ul>
<p>Example:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="s">"Test Int2Bytes() and Bytes2Int() - Value : 77"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">Int2Bytes</span><span class="p">(</span><span class="mi">77</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"Int Size : "</span> <span class="o">+</span> <span class="n">len</span><span class="p">(</span><span class="n">r</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">see</span> <span class="n">r</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">see</span> <span class="n">Bytes2Int</span><span class="p">(</span><span class="n">r</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">see</span> <span class="s">"Test Float2Bytes() and Bytes2Float() - Value 77.12"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">Float2Bytes</span><span class="p">(</span><span class="mf">77.12</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"Float Size : "</span> <span class="o">+</span> <span class="n">len</span><span class="p">(</span><span class="n">r</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">see</span> <span class="n">r</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">see</span> <span class="n">Bytes2Float</span><span class="p">(</span><span class="n">r</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">see</span> <span class="s">"Test Double2Bytes() and Bytes2Double() - Value 9999977.12345"</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">Double2Bytes</span><span class="p">(</span><span class="mf">9999977.12345</span><span class="p">)</span>
<span class="k">see</span> <span class="s">"Double Size : "</span> <span class="o">+</span> <span class="n">len</span><span class="p">(</span><span class="n">r</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">see</span> <span class="n">r</span> <span class="o">+</span> <span class="n">nl</span>
<span class="n">decimals</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="k">see</span> <span class="n">Bytes2Double</span><span class="p">(</span><span class="n">r</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="systemfunc.html" class="btn btn-neutral float-right" title="System Functions" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="mathfunc.html" class="btn btn-neutral float-left" title="Mathematical Functions" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2016-2021, Ring Team
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(false);
});
</script>
</body>
</html>