简体   繁体   English

ReactJS - 使用 Javascript 检查本地文件是否存在

[英]ReactJS - check the existence of local file using Javascript

I need to check a particular software (built by us) has been installed to the Operating system.我需要检查操作系统中是否安装了特定软件(由我们构建)。 If not need to show a proper alert message.如果不需要显示适当的警报消息。

As an alternative solution I'm going to do something like this作为替代解决方案,我将做这样的事情

After installing the software there will be file in a given path (ex: c:\\mysoftware\\config.txt)安装软件后,给定路径中会有文件(例如:c:\\mysoftware\\config.txt)

If there is any way to to check the existence of this config.txt file from Javascript then I can create a function like isSoftwareInstalled() in my reactjs application.如果有任何方法可以从 Javascript 检查这个 config.txt 文件的存在,那么我可以在我的 reactjs 应用程序中创建一个类似 isSoftwareInstalled() 的函数。

Am i doing right thing?我做的对吗? or is there any professional but simple way of doing this?或者是否有任何专业但简单的方法来做到这一点?

As far as I understand, you must be keeping this file somewhere on the server.据我了解,您必须将此文件保存在服务器上的某个位置。 If you are using Node/Express in the backend, you can use the Node File System readFile method.如果您在后端使用 Node/Express,则可以使用 Node File System readFile 方法。

https://nodejs.dev/learn/reading-files-with-nodejs https://nodejs.dev/learn/reading-files-with-nodejs

If you use some other backend language, kindly use File API in that.如果您使用其他后端语言,请在其中使用 File API。 In case, you are wondering about client-side file read, this is not possible with JS.如果您想知道客户端文件读取,这在 JS 中是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM