Advertisement
CaptainLepidus

Folder "Compression"

May 7th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //compress();
  2. {
  3.     path = working_directory + "\files\";
  4.     mask = "*.*";
  5.     textMax = 0;
  6.     file = file_find_first( path + mask , "" );
  7.     while( file != "" )
  8.     {
  9.         f = file_text_open_read( path + file );
  10.         text[ textMax ] = "[" + file + "]";
  11.         textMax = textMax + 1;
  12.         while( file_text_eof( f ) == false )
  13.         {
  14.             text[ textMax ] = file_text_read_string( f );
  15.             textMax = textMax + 1;
  16.             file_text_readln( f );
  17.         }
  18.         file_text_close( f );
  19.         file = file_find_next();
  20.     }
  21.     f = file_text_open_write( "compress.txt" );
  22.     for(i=0;i<textMax;i=i+1)
  23.     {
  24.         file_text_write_string( f , text[ i ] );
  25.         file_text_writeln( f );
  26.     }
  27.     file_text_close( f );
  28. }
  29. //decompress();
  30. {
  31.     path = working_directory + "\";
  32.     file = "compress.txt";
  33.     f = file_text_open_read( path + file );
  34.     f2 = -1;
  35.     while( file_text_eof( f ) == false )
  36.     {
  37.         txt = file_text_read_string( f );
  38.         file_text_readln( f );
  39.         if string_char_at( txt , 1 ) == "["
  40.         {
  41.             if f2 != -1
  42.             {
  43.                 file_text_close( f2 );
  44.             }
  45.             f2 = file_text_open_write( path + "newfiles\" + string_copy( txt , 2 , string_length( txt ) - 2 ) );
  46.             txt = file_text_read_string( f );
  47.             file_text_write_string( f2 , txt );
  48.         }
  49.         else
  50.         {
  51.             file_text_writeln( f2 );
  52.             file_text_write_string( f2 , txt );
  53.         }
  54.     }
  55.     file_text_close( f2 );
  56.     file_text_close( f );
  57. }
  58. //Sample compressed file
  59. [index.php]
  60. <?php echo "This is just a test.";
  61. ?>
  62. [test.txt]
  63. This is a test
  64.  
  65. Testing 123
  66. [test2.txt]
  67. This is another test
  68.  
  69. :D:D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement