用CommonDialog公共对话框选取多个文件

winform 使用CommonOpenFileDialog选择文件夹或文件 一、C#通过CommonOpenFileDialog创建文件夹更美观。然后搜索 WindowsAPICodePack,完成安装。首先,打开VS2019,通过菜单栏中的“工具”菜单。二、通过nuGet加载dll。 阅读详情

'1.在模块ModDlgSelectFileInfo中.
Option Explicit
'包含函数: GetDlgSelectFileInfo
'函数功能: 获取从CommonDialog中选取的文件信息
'自定义类型,用于DlgSelectFileInfo函数
Type DlgFileInfo
    iCount As Long
    sPath As String
    sFile() As String
End Type
'功能:     返回CommonDialog所选择的文件数量和文件名
'参数说明:  strFileName是CommonDialog.Filename
'函数类型:  DlgFileInfo。这是一个自定义类型,声明如下:
'               Type DlgFileInfo
'                   iCount As Long
'                   sPath As String
'                   sFile() As String
'               End Type
'           其中,iCount为选择文件的数量,sPath为所选文件的路径,sFile()为所选择的文件名
'注意事项:  在CommonDialog.ShowOpen后立即使用,以免当前路径被更改
'           在打开了*.pif文件后须将Filename属性置空,否则当选取多个*.pif文件后,当前路径会改变会
'           在CommonDialong.Flags属性中使用cdlOFNNoDereferenceLinks风格,就可以正确的返回*.pif文件的文件名了

Public Function GetDlgSelectFileInfo(strFilename As String) As DlgFileInfo
   
    '思路: 用CommonDialog控件选择文件后,其Filename属性值如下:
    '       1、如果选择的是"C:/Test.txt",  Filename="C:/Test.txt",    CurDir()="C:/"
    '       2、如果选择的是"C:/1/Test.txt",Filename="C:/1/Test.txt",  CurDir()="C:/1"
    '       3、如果选择的是"C:/1.txt"和"C:/2.txt",则:
    '                                   Filename="C:/1 1.txt 2.txt",  CurDir()="C:/1"
    '       因此先将路径分离开,再利用多文件之间插入的Chr$(0)字符分解各个文件名即可。
   
    Dim sPath, tmpStr As String
    Dim sFile() As String
    Dim iCount As Integer
    Dim I As Integer
   
    On Error GoTo ErrHandle
   
    sPath = CurDir()  '获得当前的路径,因为在CommonDialog中改变路径时会改变当前的Path
    tmpStr = Right$(strFilename, Len(strFilename) - Len(sPath)) '将文件名分离出来
   
    If Left$(tmpStr, 1) = Chr$(0) Then
        '选择了多个文件(表现为第一个字符为空格)
        For I = 1 To Len(tmpStr)
            If Mid$(tmpStr, I, 1) = Chr$(0) Then
                iCount = iCount + 1
                ReDim Preserve sFile(iCount)
            Else
                sFile(iCount) = sFile(iCount) & Mid$(tmpStr, I, 1)
            End If
        Next I
    Else
        '只选择了一个文件(注意:根目录下的文件名除去路径后没有"/")
        iCount = 1
        ReDim Preserve sFile(iCount)
        If Left$(tmpStr, 1) = "/" Then tmpStr = Right$(tmpStr, Len(tmpStr) - 1)
        sFile(iCount) = tmpStr
    End If
   
    GetDlgSelectFileInfo.iCount = iCount
    ReDim GetDlgSelectFileInfo.sFile(iCount)
   
    If Right$(sPath, 1) <> "/" Then sPath = sPath & "/"
    GetDlgSelectFileInfo.sPath = sPath
   
    For I = 1 To iCount
        GetDlgSelectFileInfo.sFile(I) = sFile(I)
    Next I
   
    Exit Function

ErrHandle:
    MsgBox "GetDlgSelectFileInfo函数执行错误!", vbOKOnly + vbCritical, "自定义函数错误"

End Function

'2.在Form1中,需要一个listbox,两个CommandBox,一个CommonDialog1
Option Explicit
Private Sub Command1_Click()
    Dim DlgInfo As DlgFileInfo
    Dim I As Integer
   
    On Error GoTo ErrHandle
   
    '清除List1中的项
    List1.Clear
    '选择文件
    With CommonDialog1
        .CancelError = True
        .MaxFileSize = 32767 '被打开的文件名尺寸设置为最大,即32K
        .Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks
        .DialogTitle = "选择文件"
        .Filter = "所有类型的文件(*.*)|*.*"
        .ShowOpen
        DlgInfo = GetDlgSelectFileInfo(.FileName)
        .FileName = ""      '在打开了*.pif文件后须将Filename属性置空,
                            '否则当选取多个*.pif文件后,当前路径会改变
    End With
    Dim Serial As Integer
    Serial = Form1.List1.ListCount + 1
    For I = 1 To DlgInfo.iCount
        List1.AddItem Serial & "." & DlgInfo.sPath & DlgInfo.sFile(I)
        Serial = Serial + 1
    Next I
  
    Exit Sub
   
ErrHandle:
    ' 按了“取消”按钮
End Sub
Private Sub Command2_Click()
    End
End Sub

 

利用Commondialog选择多个文件并获取各文件路径的方法(VB6.0) VB6.0编写,利用Commondialog控件选择多个文件,并获取各个文件的路径,可以直接使用!!!!!!!!!! 立即下载

相关推荐

FPGA DMA IP核使用指南

数据传输:支持从源地址到目标地址的数据传输。中断管理:提供中断信号,便于CPU处理传输完成事件。传输控制:支持传输大小、方向和暂停/恢复控制。

weixin_66634995的博客 2428

CommonDialog中同时打开多个文件实现(转)

 在Visual Basic中,通常用CommonDialog公共对话框来选择磁盘上的文件,在其Flags属性中加上cdlOFNAllowMultiselect风 格后,就允许选择多个文件。当只选择一个文件时,其文件名(包含路径)直接返回Filename属性,那么选择多个文件时呢? 如果选择了多个文件,则Filename属性返回值格式为”路径_文件名1_文件名2_…”(_为字符Chr$(0))。举

lzx1221的专栏 2540

STM32F4_DHT11数字温湿度传感器

开机的时候先检测是否有DHT11存在,如果没有,则提示错误。DHT11和DS18B20相同,传感器输出的都是未编码的二进制数字。本节我们将利用STM32F4来读取DHT11的温湿度传感器,获取环境的温度和湿度值。因此:温湿度的读取方式就是整数部分的二进制转换成十进制放在整数部分;小数部分的二进制转换成十进制放在小数部分。DHT11和MCU的一次通讯时间最大3ms,主机连续向DHT11采样的间隔建议不小于100ms。DHT11是广州奥松有限公司生产的一款温湿度一体化的数字传感器。数据分小数部分和整数部分。

light_2025的博客 3431

如何用CommonDialog实现只选择路径(转载)

用CommonDialog实现只选择路径:    Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (LpBrowseInfo As BROWSEINFO) As Long Private Declare Function SHGetPathFromIDli...

liheqian_0083 558

零基础学习大气污染模式(WRF、WRF-chem、smoke、camx等)

零基础学习大气污染模式(WRF、WRF-chem、smoke、camx等)

weixin_56135535的博客 653

模型优化系列——模型剪枝/量化概述

模型优化目的:通过减少模型大小,提高推理速度等使模型成功部署在各个硬件中并实时有效运作。

qq_61210574的博客 1293

CFolderDialog,CFolderPickerDialog选择文件夹及获得当前程序路径

CFolderDialog是从CCommonDialog类派生而来,在选择文件夹时非常好用,使用也很简单,下载地址在这里,原地址在这里   只要.h和.cpp放入工程中,并且在头文件里加#include "FolderDlg.h"就可以了。 在要弹出文件夹选择的地方   CString FoldPath;//可以自己指定文件夹路径如_T(“C://down”) CString m_st...

小猿一枚的专栏 1万+

【AI编程】Codex 进阶与高阶技巧:从熟练到精通——2026 最新教程

Skill 是 Codex 的「插件」—— 一段 Markdown 定义触发条件、输入参数和执行流程。比自定义命令更强大,支持参数化、多步骤、条件判断。

十年老程序猿,AI 疯狂研究专家,前沿硬核知识分享 192

如何从公共对话框控件中提取多个文件名称

代码如下:Private Sub Command1_Click()Dim i As Integer, title As String,  FileNames As String  With CommonDialog1      .FileName = ""      .Filter = "All Files|*.*"    过滤器指定在对话框的文件列表框中显示的文件的类型      .Flags

northwolves[狼行天下] 的专栏 2021

YOLO26 正式发布源代码!极致速度优化方案, 面向工业级落地的目标检测模型!

YOLO26 作为 Ultralytics 公司于 2025 年 9 月发布的最新一代目标检测模型,在架构设计和技术实现上展现了显著的创新。本文深入分析了 YOLO26 的核心架构改进和技术原理,重点探讨了其在边界框回归、推理流程、损失函数设计和优化算法方面的突破性进展。

魔改工程师的博客 1243

华为OD机试双机位C卷:挑选宝石 (C/C++/Python/JAVA/JS/GO)

华为OD机试双机位C卷 挑选宝石,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解。华为OD机试-挑选宝石,华为OD机考-挑选宝石。

qq_45776114的博客 1500

CommonDialog Control 控件的flag常量

object.Flags [= value] 格式都是这样~只给你贴出一个~详细的你还是下载MSDN来查吧~你要学VB 离不开它~ Value 的设置值是: value 如“设置值”中所描述,是为“打开”和“另存为”对话框指...

cjs3178095的博客 278

【Nginx学习】5步揭秘Nginx邮件代理模块:邮件代理服务器的功能与实现

Nginx的邮件代理模块(Mail Proxy Module)允许Nginx作为邮件代理服务器,支持SMTP、POP3和IMAP协议。这使得Nginx可以作为一个高性能的邮件网关,用于过滤垃圾邮件、病毒扫描、负载均衡等任务。简单来说,Nginx在这里就像是一个邮递员,负责将邮件从发件人手中安全、快速地送到收件人手中。通过上述的解析,我们可以看到Nginx在邮件代理模块中的设计和实现。从配置解析、连接处理,到协议处理、SSL/TLS加密和日志记录,每一步都至关重要。

java专栏 1312

CommonDialog

1.设置默认的文件名    CommonDialog1.FileName = "*.sql" ’默认名2。设置默认的路径    CommonDialog1.InitDir = "C:/"   默认路径3。判断是否点击消息按钮先设置   CommonDialog.CancelError   =   True    然后在点击“Cancel”时,就会产生32755   (cdlCancel)   号错

zhangting1987的专栏 1793

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

VB 用CommonDialog选择打开多个文件实例

在Visual Basic中,通常用CommonDialog公共对话框来选择磁盘上的文件,在其Flags属性中加上cdlOFNAllowMultiselect风格后,就允许选择多个文件。当只选择一个文件时,其文件名(包含路径)直接返回Filename属性,那么选择多个文件时呢? 如果选择了多个文件,则Filename属性返回值格式为”路径_文件名1_文件名2_…”(_为字符Chr$(0))。举一

kartik的专栏 4974

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

vb 关于commondialog的多选

关于commondialog的多选(如何提取文件名?)  第一种方法================================================== Function OpenFile(strFileInfor As String, strFileType As String, blnIsMulti As Boolean, OpenFileDialog As Con...

miaozk2006的专栏 913

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: MCI命令详解
下一篇: 得到MP3中隐藏的信息
SafeF8
博客等级 码龄22年 10粉丝 104原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值