本地文件系统访问 - 解决方案?

local file system access - solutions?

我发布了第二个问题。 Web 编程还很陌生,请原谅我的无知。

我有一个基于 Web 的 javascript,它访问用户 Gmail 帐户并将附件下载到 Chrome 中指定的本地下载文件夹。

然后将这些文件手动传输到另一个目录,然后 Excel VBA 脚本处理这些文件。

我希望能够跳过手动传输步骤并将文件直接保存到 Excel 正在查看的文件夹中。我可以获得 Excel 脚本来移动文件,但它仅在用户未更改 Chrome 默认下载文件夹位置时才有效,因此它并非万无一失。

我认为这对于 javascript 是不可能的,但对于其他语言是否可行,或者我是否需要一种完全不同的方法?如果可以使用其他语言,我需要查看哪一种和哪些方法?

这是应以下用户 OmegaStripes 的请求而显示的代码下载部分:

<html>

<head>Google Drive File Download Process:
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <script type="text/javascript">
        var CLIENT_ID = 'XXXXXXXXXXX';//removed for privacy
        var SCOPES = 'https://www.googleapis.com/auth/drive';

        /**
         * Called when the client library is loaded to start the auth flow.
         */

        function handleClientLoad() {
            window.setTimeout(checkAuth, 1);
        }

        /**
         * Check if the current user has authorized the application.
         */

        function checkAuth() {
            gapi.auth.authorize({
                    'client_id': CLIENT_ID,
                    'scope': SCOPES,
                    'immediate': true
                },
                handleAuthResult);
        }

        /**
         * Called when authorization server replies.
         *
         */

        function handleAuthResult(authResult) {
            var authButton = document.getElementById('authorizeButton');
            var filePicker = document.getElementById('filePicker');
            authButton.style.display = 'none';
            filePicker.style.display = 'none';
            if (authResult && !authResult.error) {
                // Access token has been successfully retrieved, requests can be sent to the API.
                filePicker.style.display = 'block';
                filePicker.onclick = downloadFile; // to allow for manual start of downloads
                window.setTimeout(downloadFile(), 5000);

            } else {
                // No access token could be retrieved, show the button to start the authorization flow.
                authButton.style.display = 'block';
                authButton.onclick = function() {
                    gapi.auth.authorize({
                            'client_id': CLIENT_ID,
                            'scope': SCOPES,
                            'immediate': false
                        },
                        handleAuthResult);
                };
            }
        }

        /**
         * Start the file download.
         *
         *
         */

        function downloadFile() {
            console.log("call drive api");
            gapi.client.load('drive', 'v2', makeRequest);
        }




        function makeRequest() {
            console.log("make request");
            var request = gapi.client.drive.files.list();
            request.execute(function(resp) {

                var x = []; //array for revised list of files to only include those not in the trash and those which have a suffix #FHM#
                for (i = 0; i < resp.items.length; i++) {
                    if (resp.items[i].labels.trashed != true && resp.items[i].title.substring(0, 5) == "#FHM#") {
                        x.push([resp.items[i].title, resp.items[i].webContentLink, resp.items[i].id]);
                    }
                }

                if (x.length == 0) {
                    document.getElementById("filePicker").value = "There are no files to download";
                }


                for (i = 0; i < x.length; i++) {
                    console.log(x.length);
                    var dlUrl = x[i][1];
                    fileIdentity = x[i][2];
                    downloadUrl(dlUrl);
                    trashFile(fileIdentity);

                    filePicker.style.display = 'none';
                    document.getElementById("bodyText").innerHTML = "<br>Download " + (i + 1) + " of " + x.length + " completed.";
                }


            });

            //window.setTimeout(function() {
            //    self.close;
            //}, 5000);

        }

        function downloadUrl(url) {
            var iframe = document.createElement("iframe");
            iframe.src = url;
            iframe.style.display = "none";
            document.body.appendChild(iframe);
        }

        function trashFile(id) {
            var requestTrash = gapi.client.drive.files.trash({
                    'fileId': id
                });
            requestTrash.execute(function(resp) {});
        }
    </script>
    <script type="text/javascript" src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
</head>


<body>
    <!--Add buttons for the user to start the process -->
    <input type="button" id="filePicker" style="display: none" value="If download does not start after 5 seconds, click here" />
    <input type="button" id="authorizeButton" style="display: none" value="Authorize" />
     <b id="bodyText"></b>
</body>

谢谢

您的代码可以尝试复制文件,如果不成功,请要求用户提供提取文件的正确路径。你说得对,Javascript 做不到。如果你想避免向用户询问路径,你可以实现一个模块来搜索文件。

有没有办法知道文件是否被提取?如果是这样,您可以使用这些知识来了解缺少成功复制是否应该触发文件搜索或文件路径请求。