Mark
Mark

Reputation: 159

Read all files in a local folder offline without using ActiveXObject or php

I'm a beginner! I need to read data inside txt files in a local folder offline. I know the folder path, but I don't know the name of every single file.

C:\mypath\first.txt
C:\mypath\second.txt
C:\mypath\third.txt
...

To read a sigle file now I use:

$.ajax({url:"C:\mypath\first.txt",
success:function(result){

//...code for storing the data in a variable...

}
});

How can i read multiple file at once without know their name? something like:

$.ajax({url:"C:\mypath\*.txt",
success:function(result){


//...code for storing the data in a variable...

}
});

Thank you for any help!

Upvotes: 0

Views: 1906

Answers (1)

gilly3
gilly3

Reputation: 91497

You can use a file picker control (ie, <input type="file" multiple />) in a supported browser and have the user select the set of files to iterate. User input is the only way to get the list of files - you can't just go mucking about in a user's file system over the internet. All you can learn about the user's system is what the user tells you (eg, through <input type="file" multiple />).

And even then, you won't be able to read the file with a simple Ajax request. Same origin policies apply to local files. It may work if you test it on your own machine, but as soon as it hits the web, it will fail.

The only way to look through a client file system without user interaction is by using a Scripting.FileSystemObject ActiveXControl on windows in a non-internet based HTML Application (.hta file). So, since you don't want to use ActiveXControls, user input is your only option.

Edit: If you are creating a FireFox add-on, you can access the file system. See the documentation at mozilla.org for details.

Upvotes: 2

Related Questions