怎样得到基于Dialog的文件的绝对路径和文件名?

博主使用文件对话框打开了D:/DATA/3.dat数据文件,询问如何获取该完整字符串路径,希望得到高手的指点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

比如说我用文件对话框打开了D:/DATA/3.dat数据文件,我怎样才能得到这个完整的字符串呢?敬请各位高手指点,不胜感谢!!!
' NC文件修改工具 - 终极PowerShell版(修复版) ' 文件名:NC_Editor_Ultimate_Fixed.vbs ' 修复内容:路径处理、错误处理、用户取消操作处理 ' 新增功能:文件查重避免二次修改 Set objFSO = CreateObject("Scripting.FileSystemObject") Set wshShell = CreateObject("WScript.Shell") ' 1. 读取上次路径(改进注册表存储方式) On Error Resume Next lastPath = wshShell.RegRead("HKCU\Software\NCEditor\LastPath") If Err.Number <> 0 Then lastPath = wshShell.ExpandEnvironmentStrings("%USERPROFILE%\Desktop") End If On Error GoTo 0 ' 2. 调用PowerShell高级文件夹选择对话框(改进版) psCommand = "Add-Type -AssemblyName System.Windows.Forms;" & _ "$$$dialog = New-Object Windows.Forms.FolderBrowserDialog;" & _ "$$dialog.Description = '请选择包含NC文件文件夹';" & _ "$$$dialog.SelectedPath = '" & lastPath & "';" & _ "$$dialog.ShowNewFolderButton = $$$true;" & _ "if ($$dialog.ShowDialog() -eq 'OK') { $dialog.SelectedPath } else { '' }" Set psExec = wshShell.Exec("powershell -WindowStyle Hidden -command """ & psCommand & """") Do While psExec.Status = 0 WScript.Sleep 100 Loop folderPath = Trim(psExec.StdOut.ReadAll) folderPath = Replace(folderPath, """", "") folderPath = Replace(folderPath, vbCrLf, "") folderPath = Replace(folderPath, vbLf, "") If folderPath = "" Then MsgBox "未选择文件夹,操作已取消", vbInformation, "提示" WScript.Quit End If If Not objFSO.FolderExists(folderPath) Then MsgBox "指定的路径不存在: " & folderPath & vbCrLf & _ "请确认路径是否正确且不包含特殊字符", vbExclamation, "错误" WScript.Quit End If wshShell.RegWrite "HKCU\Software\NCEditor\LastPath", folderPath, "REG_SZ" Set colFiles = objFSO.GetFolder(folderPath).Files successCount = 0 errorCount = 0 errorLog = "" skippedCount = 0 For Each file In colFiles If LCase(objFSO.GetExtensionName(file.Name)) = "nc" Then filePath = folderPath & "\" & file.Name ' 查重检查(简化版,只检查第一行) On Error Resume Next Set f = objFSO.OpenTextFile(filePath, 1) firstLine = f.ReadLine f.Close If Err.Number <> 0 Then errorCount = errorCount + 1 errorLog = errorLog & "文件: " & file.Name & " 读取错误: " & Err.Description & vbCrLf Err.Clear On Error GoTo 0 GoTo NextFile End If If InStr(firstLine, "G54") > 0 Then skippedCount = skippedCount + 1 errorLog = errorLog & "跳过: " & file.Name & " (文件已包含G54)" & vbCrLf On Error GoTo 0 GoTo NextFile End If ' 文件处理 On Error Resume Next Set f = objFSO.OpenTextFile(filePath, 1) content = f.ReadAll f.Close firstT = True newContent = "" For Each line In Split(content, vbCrLf) trimLine = Trim(line) If trimLine <> "" Then If Left(trimLine, 1) = "T" Then toolNum = Mid(Split(trimLine, " ")(0), 2) If firstT Then newContent = newContent & "G54" & vbCrLf newContent = newContent & "T" & toolNum & "M6" & vbCrLf newContent = newContent & "S18000M3" & vbCrLf newContent = newContent & "G43H" & toolNum & vbCrLf firstT = False Else newContent = newContent & "M5" & vbCrLf newContent = newContent & "T" & toolNum & "M6" & vbCrLf newContent = newContent & "S18000M3" & vbCrLf newContent = newContent & "G43H" & toolNum & vbCrLf End If ElseIf Not Left(trimLine, 4) = "M03 " Then newContent = newContent & line & vbCrLf End If End If Next If Right(newContent, 15) <> "G00X0Y2400Z30.000" & vbCrLf & "M5" & vbCrLf & "M30" Then newContent = newContent & "G00X0Y2400Z30.000" & vbCrLf & "M5" & vbCrLf & "M30" End If Set f = objFSO.CreateTextFile(filePath, True) f.Write newContent f.Close If Err.Number = 0 Then successCount = successCount + 1 Else errorCount = errorCount + 1 errorLog = errorLog & "文件: " & file.Name & " 写入错误: " & Err.Description & vbCrLf Err.Clear End If On Error GoTo 0 End If NextFile: Next resultMsg = "处理完成!" & vbCrLf & _ "成功修改: " & successCount & " 个NC文件" & vbCrLf & _ "跳过已修改文件: " & skippedCount & " 个" If errorCount > 0 Then resultMsg = resultMsg & vbCrLf & _ "处理失败: " & errorCount & " 个文件" & vbCrLf & _ "错误日志已复制到剪贴板" Set objHTML = CreateObject("htmlfile") Set objClip = objHTML.parentWindow.clipboardData objClip.SetData "text", errorLog End If MsgBox resultMsg, vbInformation, "完成"
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值