如何在连接到网络电脑时关闭打开的文件? [英] How can I close open files when connecting to a network pc?
本文介绍了如何在连接到网络电脑时关闭打开的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索过类似的主题,但我找不到相关内容。
我写了这个方法,基于我在网上找到的一些代码,我在控制台应用程序中使用它:
public static void OptoPurge()
{
try
{
string OptoDir = @ \\192.168.1.10\opto \\ \\lsr跨度>;
string [] ojobList = Directory.GetFiles(OptoDir, *作业跨度>);
// 删除已复制的源文件。
foreach ( string f in ojobList)
{
FileInfo fi = new FileInfo(f);
if (fi.LastWriteTime < DateTime.Now.AddMonths(-1))
// 打印要删除的文件列表
Console.WriteLine(f的ToString());
// 删除文件
File.Delete(f);
}
Console.WriteLine( OptoDir:Done ...) ;
}
catch (DirectoryNotFoundException dirNotFound)
{
Console.WriteLine(dirNotFound.Message);
}
}
我不时发现该程序与上述网络保持开放连接电脑。
任何想法如何确保工作完成后,所有连接都将关闭?
提前致谢!
P.S.对不起,如果问题很愚蠢;我是新的开发和发展C#。
解决方案
这些连接是否有问题?您可以启动运行net share命令的进程来删除这些连接
http://stackoverflow.com/questions/17604775/net-use-delete-equivalent-in-c [ ^ ]
或者看看这样的东西
http://www.codeguru.com/csharp/csharp/cs_network/windowsservices/article.php/c12357/C-Map-Network- Drive-API.htm [ ^ ]
除非这是一个问题,我只是留下它们。
I have searched for a similar topic and I haven't found something relevant.
I have written this method, based on some code I have found on the net and I use it in a console application:
public static void OptoPurge()
{
try
{
string OptoDir = @"\\192.168.1.10\opto\lsr";
string[] ojobList = Directory.GetFiles(OptoDir, "*.job");
// Delete source files that were copied.
foreach (string f in ojobList)
{
FileInfo fi = new FileInfo(f);
if (fi.LastWriteTime < DateTime.Now.AddMonths(-1))
//print a list of files to be deleted
Console.WriteLine(f.ToString());
//delete file
File.Delete(f);
}
Console.WriteLine("OptoDir: Done...");
}
catch (DirectoryNotFoundException dirNotFound)
{
Console.WriteLine(dirNotFound.Message);
}
}
From time to time, I find that the program leaves open connections to the above network pc.
Any idea how can I make sure that when job is done, all connections will be closed?
Thanks in advance!
P.S. Sorry if the question is silly; I am new in development & C#.
解决方案
Are these connections a problem? You can kick off a process that runs the "net share" command to remove these connections
http://stackoverflow.com/questions/17604775/net-use-delete-equivalent-in-c[^]
or maybe look at something like this
http://www.codeguru.com/csharp/csharp/cs_network/windowsservices/article.php/c12357/C-Map-Network-Drive-API.htm[^]
unless it's an issue I'd just leave them though.
这篇关于如何在连接到网络电脑时关闭打开的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文