导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
2023/1/13 1:53:06
标题:
Delphi第五天,求助,文件操作类
浏览:1317
加入我的收藏
楼主:
我做了一个UTF8文本编码转换ANSI编码的工具 现在有一个问题 浏览路径我用的Opentextfiledialog 进行多选操作 保存路径用的Extractfilepath 取得程序路径,并在当前目录下建立一个新目录 但是在一键转换这里,我有点不知道该用什么对象去执行操作了 比如点击一键转换 就应该是一个对象去读取Opentextfiledialog.Filename的所有文件 然后将所有的文件以ANSI编码格式全部保存到我指定的目录下 求大佬指点!
此帖子包含附件: 大小: 37.2K
----------------------------------------------
-
作者:
2023/1/13 1:57:51
1楼:
发现了一个问题! 哪怕我OpentextfileDialog属性OfallowMUlti勾选的是True,允许用户多选 但是实际上我得到的只是一个文件 请大佬指点一下啊 我应该怎么让用户以对话框的形式去选择指定的目录进行读取呢?
----------------------------------------------
-
作者:
2023/1/13 2:45:04
2楼:
我现在已经解决了,如何打开对话框选择文件夹目录 现在问题是按钮1确定了文件夹目录 那么按钮2,我该如何获取到按钮1的全部文件呢? 对这方面的语法不熟
此帖子包含附件: 大小: 70.4K
----------------------------------------------
-
作者:
2023/1/13 3:12:49
3楼:
implementation {$R *.dfm} uses System.IOUtils, Vcl.FileCtrl; procedure TForm1.Button1Click(Sender: TObject); var LStartDir : string; LDirectories : TArray<string>; LDialogTitle : string; LFolderNameLabel: string; LButtonOKText : string; begin LStartDir := 'C:\'; // ExtractFileDir(Application.ExeName); LDirectories := []; // selected dirs... LDialogTitle := 'Hello World'; LFolderNameLabel := 'Type the Dir name here:'; LButtonOKText := 'Click me!'; // // Options: TSelectDirOpt.sdAllowCreate // TSelectDirOpt.sdPerformCreate // TSelectDirOpt.sdPrompt // if SelectDirectory(LStartDir, LDirectories, [ { ??? } ], LDialogTitle, LFolderNameLabel, LButtonOKText) then begin Memo1.Lines.AddStrings(LDirectories); // all directories selected // for var D in LDirectories do begin Memo1.Lines.Add('------ Directory: ' + D + ' -------'); // Memo1.Lines.AddStrings(TDirectory.GetFiles(D)); // all files form Direcotri end; end; end;
此帖子包含附件: 大小: 25.5K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
2023/1/13 3:19:17
4楼:
screenshot
此帖子包含附件: 大小: 20.1K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
2023/1/13 3:36:34
5楼:
大佬们能不能用中文注释啊 英文看的很吃力,老要翻译
----------------------------------------------
-
作者:
2023/1/13 3:43:27
6楼:
我不是用编辑框读取啊,我是直接点击一键转换 然后就读取到按钮1的文本数据 现在不知道该用什么语法以及对象去执行读取按钮1的文件数据
----------------------------------------------
-
作者:
2023/1/13 8:39:15
7楼:
取filesnames数组的内容
----------------------------------------------
-
作者:
2023/1/13 9:11:48
8楼:
@michael20130904 我和你有同样的困难:我必须把所有的文本都翻译成中文。 var LFileNames:TArray<string>; LDirectories:TArray<string>; ... SelectDirectory(LStartDir, LDirectories, [ { ??? } ], LDialogTitle, LFolderNameLabel, LButtonOKText) LStartDir = 起始目录 LDirectories = 主目录里面的所有目录,点击“确定”按钮后 (不重要) LDialogTitle = 窗口标题 (不重要)LFolderNameLabel = 目录名称“标签”中的文本 (不重要)LButtonOKText = “确定”按钮的文本 if (Length(LDirectories) > 0) then ... LFileNames := TDirectory.GetFiles( LDirectories[ 0 ] ); // 0, 1, 2, 3, ....Length(LDirectories)-1 ... if (Length(LFileNames) > 0) then ShowMessage( LFileNames[ 0 ] ); // 0, 1, 2, 3, ....Length(LFileNames)-1
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
2023/1/13 9:12:36
8楼:
//very easy... procedure TForm1.Button1Click(Sender: TObject); const LFilter = '*.txt;*.pas;*.dfm'; begin var LOpenDLG: TOpenDialog := TOpenDialog.Create(Self); LOpenDLG.Filter := LFilter + '|' + LFilter; LOpenDLG.Title := '可多选'; LOpenDLG.Options := LOpenDLG.Options + [ofAllowMultiSelect]; if LOpenDLG.Execute(Application.Handle) then begin for var sFilename in LOpenDLG.Files do ShowMessage('我是' + sFilename); end; LOpenDLG.Free; end;
----------------------------------------------
delphi 是兴趣,和工作无关,即使它倒闭。又不靠它 delphi 吃饭,怕甚?
作者:
tuao (tuao)
★☆☆☆☆
-
盒子活跃会员
2023/1/13 9:24:19
8楼:
TDirectory.GetFiles(D)返回一个文件名数组,获取这个数组就可得到全部文件。 如果要获取指定文件名或扩展名的文件,请自行搜索TDirectory.GetFiles的用法。
----------------------------------------------
tuao
作者:
2023/1/13 17:28:07
9楼:
大佬们,请教下 我现在按钮1目录里面的文件全部读取到了 但是怎么才能将读取到的文件直接保存呢? 用什么语法实现?
此帖子包含附件: 大小: 58.3K
----------------------------------------------
-
作者:
2023/1/13 18:12:45
10楼:
在线等大佬
----------------------------------------------
-
作者:
2023/1/13 18:15:38
11楼:
这种工具我干过还获取了系统支持的 各个国家ansi编码的 代号
----------------------------------------------
[alias] co = clone --recurse-submodules up = submodule update --init --recursiveupd = pullinfo = statusrest = reset --hard懒鬼提速https://www.cctry.com/ >http://qalculate.github.io/downloads.htmlhttps://www.cctry.com/
作者:
2023/1/14 1:30:37
12楼:
procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Lines.LoadFromFile('d:\这种工具我干过还获取了系统支持的.这种', TEncoding.UTF8); end;
此帖子包含附件: 大小: 14.5K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
2023/1/14 21:28:49
13楼:
我已经做好了,完美解决了!
----------------------------------------------
-