Windows Directory Tree into Database dump
 
With this PHP Script, you can create a dumpfile of a directory tree file which can be imported into a database easily. Its easy for advanced programmers only... Ask if you have a question.

This is how you can generate a directory tree file: Open a command line under windows and type the following command inside:
C:>tree /F /A > tree.txt

This will generate a file which will look like this:
|  AUTOEXEC.BAT
|  AUTOEXEC.CAM
|  
+---Folder
|  |  somelogfile.LOG
|  |  someexe.EXE
|  |   
|  ---Subfolder
|      somefile.sql
|      somedocument.doc
ando so on...

Now, save the file and the script which will follow on your webserver and let it run. Here is the php script:
<?php
$treefile = file_get_contents("tree.txt", "r");
$line = explode("n", $treefile);
$start=0;
$currentfolder="folder0";
$thisisfolder = "no";
while($start < 26869)
 {
 $currentline = $line[$start];

 // Wenn es ein Folder ist, dann:
 // Die Position ausfindig machen und sagen, welches der aktuelle ist.

 if(substr($currentline,57,3) == "---")
  { $currentfolder="folder15";
  $folder15 = substr($currentline,60);
  $thisisfolder = "yes";}

 elseif(substr($currentline,53,3) == "---")
  { $currentfolder="folder14";
  $folder14 = substr($currentline,56);
  $thisisfolder = "yes";}

 elseif(substr($currentline,49,3) == "---")
  { $currentfolder="folder13";
  $folder13 = substr($currentline,52);
  $thisisfolder = "yes";}

 elseif(substr($currentline,45,3) == "---")
  { $currentfolder="folder12";
  $folder12 = substr($currentline,48);
  $thisisfolder = "yes";}

 elseif(substr($currentline,41,3) == "---")
  { $currentfolder="folder11";
  $folder11 = substr($currentline,44);
  $thisisfolder = "yes";}

 elseif(substr($currentline,37,3) == "---")
  { $currentfolder="folder10";
  $folder10 = substr($currentline,40);
  $thisisfolder = "yes";}

 elseif(substr($currentline,33,3) == "---")
  { $currentfolder="folder9";
  $folder9 = substr($currentline,36);
  $thisisfolder = "yes";}

 elseif(substr($currentline,29,3) == "---")
  { $currentfolder="folder8";
  $folder8 = substr($currentline,32);
  $thisisfolder = "yes";}

 elseif(substr($currentline,25,3) == "---")
  { $currentfolder="folder7";
  $folder7 = substr($currentline,28);
  $thisisfolder = "yes";}

 elseif(substr($currentline,21,3) == "---")
  { $currentfolder="folder6";
  $folder6 = substr($currentline,24);
  $thisisfolder = "yes";}

 elseif(substr($currentline,17,3) == "---")
  { $currentfolder="folder5";
  $folder5 = substr($currentline,20);
  $thisisfolder = "yes";}

 elseif(substr($currentline,13,3) == "---")
  { $currentfolder="folder4";
  $folder4 = substr($currentline,16);
  $thisisfolder = "yes";}

 elseif(substr($currentline,9,3) == "---")
  { $currentfolder="folder3";
  $folder3 = substr($currentline,12);
  $thisisfolder = "yes";}

 elseif(substr($currentline,5,3) == "---")
  { $currentfolder="folder2";
  $folder2 = substr($currentline,8);
  $thisisfolder = "yes";}

 elseif(substr($currentline,1,3) == "---")
  { $currentfolder="folder1";
  $folder1 = substr($currentline,4);
  $thisisfolder = "yes";}

 if($currentfolder=="folder0") { $datei=substr($currentline,4); }
 if($currentfolder=="folder1") { $datei=substr($currentline,8); }
 if($currentfolder=="folder2") { $datei=substr($currentline,12); }
 if($currentfolder=="folder3") { $datei=substr($currentline,16); }
 if($currentfolder=="folder4") { $datei=substr($currentline,20); }
 if($currentfolder=="folder5") { $datei=substr($currentline,24); }
 if($currentfolder=="folder6") { $datei=substr($currentline,28); }
 if($currentfolder=="folder7") { $datei=substr($currentline,32); }
 if($currentfolder=="folder8") { $datei=substr($currentline,36); }
 if($currentfolder=="folder9") { $datei=substr($currentline,40); }
 if($currentfolder=="folder10") { $datei=substr($currentline,44); }
 if($currentfolder=="folder11") { $datei=substr($currentline,48); }
 if($currentfolder=="folder12") { $datei=substr($currentline,52); }
 if($currentfolder=="folder13") { $datei=substr($currentline,56); }
 if($currentfolder=="folder14") { $datei=substr($currentline,60); }
 if($currentfolder=="folder15") { $datei=substr($currentline,64); }

 // Break aus Ordnern entfernen
 $folder1 = str_replace("r","",$folder1);
 $folder2 = str_replace("r","",$folder2);
 $folder3 = str_replace("r","",$folder3);
 $folder4 = str_replace("r","",$folder4);
 $folder5 = str_replace("r","",$folder5);
 $folder6 = str_replace("r","",$folder6);
 $folder7 = str_replace("r","",$folder7);
 $folder8 = str_replace("r","",$folder8);
 $folder9 = str_replace("r","",$folder9);
 $folder10 = str_replace("r","",$folder10);
 $folder11 = str_replace("r","",$folder11);
 $folder12 = str_replace("r","",$folder12);
 $folder13 = str_replace("r","",$folder13);
 $folder14 = str_replace("r","",$folder14);
 $folder15 = str_replace("r","",$folder15);

 // Pfad herausfinden
 $lw = "Q:"; $zc = "\";
 if($currentfolder=="folder0") { $path = $lw.$zc; }
 if($currentfolder=="folder1") { $path = $lw.$zc.$folder1.$zc; }
 if($currentfolder=="folder2") { $path = $lw.$zc.$folder1.$zc.$folder2.$zc; }
 if($currentfolder=="folder3") { $path = $lw.$zc.$folder1.$zc.$folder2.$zc.$folder3.$zc; }
 //And so on.....

 // Wenn Dateiname leer ist dann nicht anzeigen:
 if ($datei == "" OR $datei == "r") { $thisisfolder = "yes"; }

 // Datei anzeigen wenns eine Datei ist:
 if( $thisisfolder != "yes" )
  {
  $row1 = "Medium1t";
  $zeile = $row1.$path."t".$datei;
  echo str_replace("\\","\",$zeile);
  }

 $thisisfolder = "no";
 $start++;
 }
?>

Performing this script over a directory treefile will give you an output which will format it like this:

Medium1<tabulator>Path<tabulator>File1
Medium1<tabulator>Path<tabulator>File2
Medium1<tabulator>Path<tabulator>File3

This script can help you indexing your backup - lets say you backed up Music on some CDs. After, you can search your database after the filename and it will give you which medium its on and what the path is...
 
admin / Dec 10, 2003
   
 
 
Login: 
Pass: 
 
 
     
     
2004 - 2019 / lookass.ch
makememad@lookass.ch