我一直在努力使用需要将最新文件从文件服务器复制或下载到本地驱动器文件夹的脚本。这就是我想出的:
[String]$LocalServer = "\\IP_address\D:\Interfaces\"
[String]$File_Name = "MK." + (Get-Date).ToString("ddMMyy") + ".tar.gz" #file name is example MK.040418.tar.gz
[String]$Path = "C:\Localfolder"
[String]$Username = "admin"
[String]$Password = "Admin123"
Copy-Item -Path {$LocalServer + "\" + $FileName} - Destination {$LocalPath}
#$WebClient = New-Object System.Net.WebClient
#$WebClient.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
#$WebClient.DownloadFile($LocalServer, $FileName)
答案 0 :(得分:1)
您的代码存在一些问题:
您无需使用FileReader fileReader = new FileReader("D://MyWork/Mobile.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
while (bufferedReader.read() != -1) {
String line = bufferedReader.readLine();
lineNum++;
Pattern pattern = Pattern.compile("^(0|91)?[7-9]\\d{9}(\\b|$)");
Matcher matcher = pattern.matcher(line);
while (matcher.find()) {
System.out.println("at line....:" + lineNum +
".....found....." + matcher.group() +
"...start..." + matcher.start() +
"..end..." + matcher.end());
}
使用Powershell包装参数。
您的变量为{}
,但您使用$File_Name
(缺少$FileName
)_
命令。
Copy-Item
以$LocalServer
结尾,您还在使用\
添加一个,因此该路径最终会出现双斜杠:$LocalServer + "\" + $FileName
修正这些点,命令应为:
\\IP_address\D:\Interfaces\\MK.040418.tar.gz