Ring Documentation Walkthrough #12 – Files

Welcome to the new chapter, we will discuss today some of the files functions.

This part is easy to understand.

  • Read()
    This function basically reads the content in a file and returns it as a string.
    For an example:

    content = read('info.txt')
    see content
    content_exe = read('chrome.exe')
    see content_exe
    

  • Write()
    You can use this function to write string or binary files.

    content = 'Surrender'
    write('message.txt', content)
    

    We can using it in copying files too:

    pdf1 = read('ringdoc.pdf')
    pdf2 = write('ringdoc2.pdf', pdf1)
    

  • Dir()
    It basically returns all the files & sub directories found in a directory.
    It returns a list format, every item in the list is actually a list contains two items : 1- file/sub directory name, 2- Type (0 for File, 1 for Directoy)

    tree = dir('folder')
    for item in tree
       see item[1] #output: the file/directory name
       if item[2] = 0 see 'File' + nl
       but item[2] = 1 see 'Directory' + nl
       ok
    next
    

  • Rename()

    rename('tweeter.ico', 'twitter.png')

  • Remove()
    For deleting files.

    remove('setup.exe')
    

That’s it, next part i will discuss some of the left functions.

See you in the next one.

amrESSAM.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s