Check File exist in Folder using Javascript

心不动则不痛 提交于 2021-02-05 12:31:10

问题


I want to check a file exist in folder. Below code is while i'm trying to many times is not working.

<!DOCTYPE html>
<html>
<head>
<script>
function Start()
{
var path = "X:\ApplicationFiles\Journals\TandF\RJHR\Vol00000\180008\ML\IProof\TF-RJHR180008.xml";
if (File.Exists(path))
{
document.getElementById("Stage").innerHTML = "exists";
}
}
</script>
</head>
<body>
<table border="1">
<thead>
<tr><th>Job ID</th><th>JID</th><th>Article ID</th><th>Intrnl ID</th><th>Due Date</th><th>Current Status</th></tr>
</thead>
<tbody>
<tr><td>T76825</td><td>RJHR</td><td>1445583</td><td>180008</td><td>01-Mar-18</td><td><p id="Stage"/></td></tr>
</tbody>
</table>
</body>
</html>

回答1:


This wont work because your browser does not have access to your file system.

you can run this from a node.js server

see https://en.wikipedia.org/wiki/JavaScript#Security




回答2:


You can't access local files in modern web browsers. There is the HTML5 File API, but that involves direct user actions, you can't just use whatever files you please.




回答3:


There is no way you cant access files using your browser , JavaScript is a view language its interact only with the browser, to be able to access local file you need to use a back end platform such as NodeJs or Php




回答4:


As I learned years ago you cannot access local file system with JS from browser, but things change. You can find more info here:

Local file access with javascript

The article directs you to MDN but the solution works only in certain browsers:

https://developer.mozilla.org/en-US/docs/Web/API/File_and_Directory_Entries_API



来源:https://stackoverflow.com/questions/49011467/check-file-exist-in-folder-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!