-3

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>
James Z
  • 12,209
  • 10
  • 24
  • 44
Karthick
  • 17
  • 1
  • 2

4 Answers4

2

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

1

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.

meskobalazs
  • 15,741
  • 2
  • 40
  • 63
1

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

Abslen Char
  • 3,071
  • 3
  • 15
  • 29
0

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

Attis
  • 573
  • 1
  • 7
  • 19
  • 1
    That API creates a virtual file system that lets the web app read and write its own files there. It still can't access aribtrary files on the user's computer. – JJJ Feb 27 '18 at 15:18