New file |
| | |
| | | package com.mes.common; |
| | | |
| | | import jcifs.smb.NtlmPasswordAuthentication; |
| | | import jcifs.smb.SmbFile; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | public class SmbTool { |
| | | public static String USER_DOMAIN=null;//共享计算机ip "192.168.3.102"; |
| | | public static String USER_ACCOUNT=null;//登录共享文件夹 用户名 "aaa",如果是共享是无密码模式 此处值设置为 null; |
| | | public static String USER_PWS=null;//登录共享文件夹 密码"guoyujie",如果是共享是无密码模式 此处值设置为 null; |
| | | |
| | | /** |
| | | * test 测试示例 |
| | | */ |
| | | private void test() |
| | | { |
| | | int index= SmbTool.getDescriptionIndex("log","P20240522");//输入切割机共享文件夹名字、工程号,返回当前工程正在切割的版图号 |
| | | System.out.print(index); |
| | | } |
| | | /** |
| | | * smbGetall 返回指定目录下的文件名字 |
| | | * @param GoalUrl 远端目录("smb://192.168.2.100//ceshi//") |
| | | */ |
| | | public static String[] smbGetallFilenames(String GoalUrl) { |
| | | NtlmPasswordAuthentication auth=new NtlmPasswordAuthentication(USER_DOMAIN,USER_ACCOUNT,USER_PWS); |
| | | List<String> filenames=new ArrayList<>(); |
| | | try { |
| | | SmbFile remoteFile = new SmbFile(GoalUrl,auth); |
| | | if (remoteFile == null) { |
| | | return filenames.toArray(new String[]{}); |
| | | } |
| | | if (remoteFile.exists()) |
| | | { |
| | | SmbFile[] listFiles = remoteFile.listFiles(); |
| | | for(int i = 0; i < listFiles.length; i++) { |
| | | filenames.add(listFiles[i].getName()); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return filenames.toArray(new String[]{}); |
| | | } |
| | | /** |
| | | * getDescriptionIndex 根据工程号,返回当前正在切割的版图号 |
| | | * @param folderName 共享文件夹名字 |
| | | * @param project_no 工程号 |
| | | */ |
| | | public static int getDescriptionIndex(String folderName,String project_no) |
| | | { |
| | | SimpleDateFormat formatter= new SimpleDateFormat("yyyyMMdd"); |
| | | Date date = new Date(System.currentTimeMillis()); |
| | | System.out.println(formatter.format(date)); |
| | | String[] getfilenames= smbGetallFilenames("smb://"+USER_DOMAIN+"/"+folderName+"/"+formatter.format(date)+"/"); |
| | | for (int i = 0; i < getfilenames.length; i++) { |
| | | String[] splitvalues= getfilenames[i].split("_"); |
| | | if (splitvalues.length>=3&&splitvalues[1].trim().equals(project_no)) |
| | | { |
| | | String[] indexstr= splitvalues[2].trim().split("\\."); |
| | | if (indexstr.length>1) { |
| | | return Integer.parseInt(indexstr[0]); |
| | | } |
| | | } |
| | | } |
| | | return -1; |
| | | } |
| | | } |