标签: filesystemwatcher

FileSystemWatcher和网络断开?

如何让它在网络中运行?它工作然后它没有理由停止工作(可能因为网络不完美).

.net c# filesystemwatcher .net-2.0

6
推荐指数
1
解决办法
3046
查看次数

FileSystemWatcher无法访问网络驱动器

我试图使用Windows服务在某些服务器路径上运行文件观察程序.我正在使用我的Windows登录凭证来运行该服务,并且能够从我的登录中访问此"someServerPath".但是,当我从FileSystemWatcher那样做时,它抛出:

目录名\ someServerPath无效"异常.

var fileWatcher = new FileSystemWatcher(GetServerPath()) 
    {
        NotifyFilter=(NotifyFilters.LastWrite|NotifyFilters.FileName),
        EnableRaisingEvents=true,
        IncludeSubdirectories=true
    };

public static string GetServerPath() 
{
    return string.Format(@"\\{0}", FileServer1);              
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮我这个吗?

c# windows-services filesystemwatcher

6
推荐指数
2
解决办法
2万
查看次数

映射网络驱动器上的FileSystemWatcher

在实施FSW以监视映射的网络驱动器时,是否应考虑特殊注意事项(权限除外).如果驱动器失去连接,FSW会抛出异常吗?如果不是(或者如果我只是捕获/处理该异常),那么轮询DirectoryInfo.Exists属性以验证连接是否足够?

c# filesystemwatcher exception-handling mapped-drive

6
推荐指数
1
解决办法
8653
查看次数

C#跟踪复制的文件

我试图跟踪用户和其他应用程序复制的文件.FileSystemWatch仅包含Changed,Created,Deleted,Disposed,Error和Renamed事件.当复制功能访问文件或复制新文件时,它不会触发事件.

有没有一种方法来监控Windows的复制事件/功能?

c# windows filesystemwatcher copy

6
推荐指数
1
解决办法
2596
查看次数

如何获取使用FileSystemWatcher创建的新文件的名称?

我正在使用FileSystemWatcher监视文件夹.如果我将文件下载到那里,我如何获得该下载文件的名称?例如,如果我下载了一个名为TextFile.txt的文件,我将如何将其作为字符串返回?我假设这将适用于所有四个触发器(更改,创建,删除,重命名)?我将IncludeSubdirectories设置为true,因此它应该能够做到这一点.

.net c# filesystemwatcher

6
推荐指数
1
解决办法
6069
查看次数

JDK 7 WatchService API 和 NFS 文件共享

我们正在使用[WatchService][1]API (JDK 7) 来跟踪在我的系统中创建的文件。到目前为止,它工作正常。我的系统上创建的每个文件都由我的程序跟踪。

但是我们在使用NFS时遇到了麻烦(我们跟踪的目录实际上存在于局域网中的另一台计算机上)。

WatchService 不起作用。

谁能告诉我如何解决这种情况?我如何设置 NFS 以支持 Java 7 WatchServiceAPI,或者谁能告诉我一个更好的库。

谢谢大家

java filesystems filesystemwatcher nfs java-io

6
推荐指数
1
解决办法
4035
查看次数

从FileSystemWatcher错误中恢复的最佳做法是什么?

经过一个FileSystemWatcher.Error引发事件,我不知道下一步该怎么做的线索.例外可以是[相对]次要的,例如

目录中一次更改太多

这不会影响观察者的观看过程,但它也可能是一个大问题 - 例如被监视的目录被删除,在这种情况下观察者不再起作用.

我的问题是处理Error事件的最佳方法是什么?

.net c# filesystemwatcher exception-handling

6
推荐指数
1
解决办法
5563
查看次数

express-ws如何定期检查自定义事件并自动执行操作

我正在使用express-ws https://www.npmjs.com/package/express-ws(有助于为express和websocket客户端创建服务器的API).

app.ws('/', function(ws, req) {
  console.log("New connection")
  if (content.length > 0) {
    console.log(content)
    ws.send(content)
  }
  ws.on('message', function(msg, flags) {
    console.log("Received "+ msg);
  });
  ws.on('data', function(msg, flags) {
    var data = []; // List of Buffer objects
    res.on("data", function(chunk) {
      data.push(chunk); // Append Buffer object
      console.log(data)
    })
  })
});
Run Code Online (Sandbox Code Playgroud)

现在您可以看到上面的代码,无论何时创建连接,它都会检查内容的长度,并在超过0时向客户端发送conetent.

遵循路由器代码,在Web请求上更新文件.如果在连接创建后的某个时间(如果此文件被修改),此连接不知道它,因此不会调用此函数,因此不会调用send函数.我也试过fs.watch但是我无法让它工作.

router.post('/run_restart', function(req, res, next) {
  text = '{"to_do": "run_test", "devices":"all", "argv": { "test": "' + req.body.cmd + '", "cycles": "' + req.body.cycles + '", "awake_for": "' + req.body.wt …
Run Code Online (Sandbox Code Playgroud)

filesystemwatcher websocket node.js express

6
推荐指数
2
解决办法
1833
查看次数

C# 等待外部应用程序关闭文件

当外部应用程序关闭已知文件时,是否有我可以捕获的事件?

例如,用户正在 Excel 中编辑工作簿,我想在用户完成处理并关闭该文件后立即读取该文件。

我当前的解决方案是使用 FileSystemWatcher 和 Timer 的组合。FileSystemWatcher 将检测何时对文件进行更改,并启动一个运行计时器的新线程来检查文件何时关闭(通过try-catch)但是我不认为这是一个好的解决方案。如果用户忘记关闭文件并回家过周末,那么我的计时器一直在运行会感觉很浪费。如果我增加计时器的间隔,那么我的程序将不会响应。有没有不涉及轮询的解决方案?

编辑:用我所拥有的代码示例进行更新

    private System.Windows.Forms.Timer processTimer;
    private string blockedFile;

    // Starts here. File changes were detected.
    private void OnFileSystemWatcher_Changed(object source, FileSystemEventArgs e)
    {
        FileSystemWatcher fsw = (FileSystemWatcher)source;
        string fullpath = Path.Combine(fsw.Path, fsw.Filter);
        StartFileProcessing(fullpath);
    }

    private void StartFileProcessing(string filePath)
    {
        if (isFileOpen(new FileInfo(filePath)))
        {
            blockedFile = filePath;
            processTimer = new System.Windows.Forms.Timer();
            processTimer.Interval = 1000; // 1 sec
            processTimer.Tick += new EventHandler(processTimer_Elapsed);
            processTimer.Enabled = true;
            processTimer.Start(); 
        }
        else
            ProcessFile(filePath);

    }

    private void …
Run Code Online (Sandbox Code Playgroud)

c# filesystemwatcher

6
推荐指数
0
解决办法
2228
查看次数

使用FileSystemWatcher警告多个文件是否同时更改

我对powershell很新.以下代码由BigTeddy创建,他获得了全部功劳(我还使用While循环进行了一些更改)

我想知道如何创建if/else语句,以便如果同时更改/编辑/创建/删除多个文件(比如同时编辑了10个文件),将创建一个日志文件,说明这些列表文件已在此特定时间同时编辑.

以下powershell脚本BigTeddy创建的基本上是在更改/编辑/创建/删除时,更改时间和编辑了哪些文件时发出日志文件(以及powershell ISE的输出).

 param(
        [string]$folderToWatch = "C:\Users\gordon\Desktop\powershellStart"
      , [string]$filter        = "*.*"
      , [string]$logFile       = 'C:\Users\gordon\Desktop\powershellDest\filewatcher.log'
    )

    # In the following line, you can change 'IncludeSubdirectories to $true if required.
    $fsw = New-Object IO.FileSystemWatcher $folderToWatch, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
    $timeStamp           #My changes
    $timeStampPrev = $timeStamp         #My changes
# This script block is used/called by all 3 events and:
# appends the event to a log file, as well as reporting the event back to the console …
Run Code Online (Sandbox Code Playgroud)

powershell filesystemwatcher

6
推荐指数
1
解决办法
132
查看次数