(已解决)批量创建文件,再次谢谢3MILE哥,chenronting,xiehuahere,user3000
本帖最后由 xyhqqaa 于 2011-11-11 02:34 编辑新手求助.最近遇到个问题.我想批量创建XX类型的文件.但是不知道使用_filecreat跟_fileanddirctreat如何实现批量生成文件.而且文件名长度要一致..囧..比如我要生成100个TXT文件.第一个为新建文件001.txt或者新建文件(001).txt,第二个为新建文件002...................假如我要生成1000个TXT文件..那么名称生成又为新建文件0001.txt..........依次类推....其实最纠结的是这个文件名的生成..使用批处理是可以生成文件.但是文件名俺就不知道该如何生成刚才的样式...跪求批处理生成方式也行..#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include<file.au3>
#include <array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 369, 251, 192, 114, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
$Form1context = GUICtrlCreateContextMenu()
$MenuItem1 = GUICtrlCreateMenuItem("清空", $Form1context)
$Group1 = GUICtrlCreateGroup("Group1", 0, 8, 361, 153)
$Label1 = GUICtrlCreateLabel("路径:", 8, 40, 48, 17)
$Label2 = GUICtrlCreateLabel("文件名:", 8, 80, 52, 17)
$Input1 = GUICtrlCreateInput("", 64, 32, 209, 28)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("", 64, 72, 209, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("浏览", 288, 32, 65, 25)
$Button1context = GUICtrlCreateContextMenu($Button1)
$Label3 = GUICtrlCreateLabel("数量:", 8, 120, 40, 17)
$Input3 = GUICtrlCreateInput("", 64, 112, 73, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$Combo1 = GUICtrlCreateCombo("", 280, 72, 73, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $CBS_SIMPLE))
GUICtrlSetData(-1, ".txt|.jpg|.doc|.xls|.exe")
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button2 = GUICtrlCreateButton("批量创建", 56, 176, 257, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$files = FileSelectFolder("选择相应文件夹",@WorkingDir)
GUICtrlSetData($input1,$files)
Case $Button2
$way = GUICtrlRead($input1)
$name = GUICtrlRead($input2)
$style = GUICtrlRead($Combo1)
_FileAndDirCreate($way&"\"&$name&$style)
case $MenuItem1
GUICtrlSetData($input1,"")
EndSwitch
WEnd
Func _FileAndDirCreate($FilePach)
Dim $szDrive, $szDir, $szFName, $szExt
$arrPath = _PathSplit($FilePach, $szDrive, $szDir, $szFName, $szExt)
If Not FileExists($FilePach) Then
If $szExt = '' Then
DirCreate($FilePach)
Else
_FileCreate($FilePach)
EndIf
Else
For $i = 0001 To 1000
If Not FileExists($szDrive & $szDir & $szFName & '(' & $i & ')' & $szExt) Then ExitLoop
Next
If $szExt = '' Then
DirCreate($szDrive & $szDir & $szFName & '(' & $i & ')')
Else
_FileCreate($szDrive & $szDir & $szFName & '(' & $i & ')' & $szExt)
EndIf
EndIf
MsgBox("","",$szDrive)
EndFunc ;==>_FileAndDirCreate
那我给出关键的部分吧,希望你能看的懂
#Include <File.au3>
$wenjianleixing='txt'
Global $kaishi=1
Global $jieshu = 11
For $i = $kaishi To $jieshu
_FileCreate(@ScriptDir & '\' & $i & '.' & $wenjianleixing)
;While Not FileExists(@ScriptDir & '\' & $i & '.' & $wenjianleixing)
;Sleep(100)
;WEnd
Sleep(100)
Next
中间的是注释掉的,你如果不需要就去掉吧,一个思路罢了。 不要意思,又看了一下你的说明,感觉我些的不对头,不过实在没有真正明白楼主的意思。请说明白点,谢谢 回复 3# chenronting
我的想法是,我想批量生成文件.自动生成的文件假如为少99个..则命名为新建文档01.txt ,新建文档02.txt,新建文档03.txt..........新建文档99.txt ,文件字符长度要一样...假如我新建100-999个.则文件名新建文档001.txt,新建文档002.txt,新建文档003.txt........新建文档999.txt,...刚好生成的字符为三位.这样命名长度一样...依次类推
囧..不知道这样说明白了没..不过谢谢你的帮助,我稍微有点头绪...剩下就是循环判断生成文件个数命来名文件....... 现在有点头大...当文件个数1-9时候.文件名不加0 ,当文件数9-99的时候 1-9的前面个数需要加0.但排除10-99.
.当文件个数100-999的时候 1-9前面需要加00 ,10-99前面需要加0 但排除100-999....这判断该怎么同时判断..生成..大神.大哥,大爷们{:face (319):}...新手迷茫死了 #include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include<file.au3>
#include <array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 369, 251, 192, 114, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
$Form1context = GUICtrlCreateContextMenu()
$MenuItem1 = GUICtrlCreateMenuItem("清空", $Form1context)
$Group1 = GUICtrlCreateGroup("Group1", 0, 8, 361, 153)
$Label1 = GUICtrlCreateLabel("路径:", 8, 40, 48, 17)
$Label2 = GUICtrlCreateLabel("文件名:", 8, 80, 52, 17)
$Input1 = GUICtrlCreateInput("", 64, 32, 209, 28)
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("", 64, 72, 209, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("浏览", 288, 32, 65, 25)
$Button1context = GUICtrlCreateContextMenu($Button1)
$Label3 = GUICtrlCreateLabel("数量:", 8, 120, 40, 17)
$Input3 = GUICtrlCreateInput("", 64, 112, 73, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$Combo1 = GUICtrlCreateCombo("", 280, 72, 73, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $CBS_SIMPLE))
GUICtrlSetData(-1, ".txt|.jpg|.doc|.xls|.exe")
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button2 = GUICtrlCreateButton("批量创建", 56, 176, 257, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$files = FileSelectFolder("选择相应文件夹", @WorkingDir)
GUICtrlSetData($Input1, $files)
Case $Button2
$way = GUICtrlRead($Input1)
$name = GUICtrlRead($Input2)
$style = GUICtrlRead($Combo1)
_FileAndDirCreate($way & "\" & $name & $style)
Case $MenuItem1
GUICtrlSetData($Input1, "")
EndSwitch
WEnd
Func _FileAndDirCreate($FilePach)
Dim $szDrive, $szDir, $szFName, $szExt
$arrPath = _PathSplit($FilePach, $szDrive, $szDir, $szFName, $szExt)
If Not FileExists($FilePach) Then
If $szExt = '' Then
;~ DirCreate($FilePach)
Else
;~ _FileCreate($FilePach)
EndIf
Else
Local $str
Local $len = StringLen(GUICtrlRead($Input3))
For $i = 1 To GUICtrlRead($Input3)
$str &= $FilePach & StringFormat('%0' & $len & 'd', $i) & @CRLF
Next
MsgBox(0, 0, $str)
EndIf
EndFunc ;==>_FileAndDirCreate 同样给一个思路。假如是少于99个:#Include <File.au3>
For $i = 0 To 99
_FileCreate(@ScriptDir & '\' & StringFormat("%02u", $i) & '.txt')
Sleep(100)
Next 真佩服你了, 都混到中级会员了, 连AU3基础都还不会!
判断不是有判断的语句吗?
if ... then...
select... endselect
但用函数 stringformat 更能简洁达到你的要求. 囧....水人一个.只会发水帖.....楼上.您批评的是...正在慢慢学习..囧...俺错了....伸手影响独立思考....以后努力自己动手...还有谢谢大家.谢谢3mile哥.谢谢xiehuahere..谢谢chenronting.....俺新手会努力的 本帖最后由 xyhqqaa 于 2011-11-11 00:55 编辑
代码整理如下..不知道会不会乱七八糟的- -///
看懂StringFormat这参数估计要我蛋疼几天...继续努力..谢谢大家#NoTrayIcon
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include<file.au3>
#include <array.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 369, 251, 192, 114, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
$Form1context = GUICtrlCreateContextMenu()
$MenuItem1 = GUICtrlCreateMenuItem("清空", $Form1context)
$MenuItem2 = GUICtrlCreateMenuItem("", $Form1context)
$MenuItem3 = GUICtrlCreateMenuItem("退出", $Form1context)
$Group1 = GUICtrlCreateGroup("Group1", 0, 8, 361, 153)
$Label1 = GUICtrlCreateLabel("路径:", 8, 40, 48, 17)
$Label2 = GUICtrlCreateLabel("文件名:", 8, 80, 52, 17)
$Input1 = GUICtrlCreateInput("", 64, 32, 209, 28)
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("", 64, 72, 209, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("浏览", 288, 32, 65, 25)
$Button1context = GUICtrlCreateContextMenu($Button1)
$Label3 = GUICtrlCreateLabel("数量:", 8, 120, 40, 17)
$Input3 = GUICtrlCreateInput("", 64, 112, 73, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$Combo1 = GUICtrlCreateCombo("", 280, 72, 73, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $CBS_SIMPLE))
GUICtrlSetData(-1, ".txt|.jpg|.doc|.xls|.exe||")
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button2 = GUICtrlCreateButton("批量创建", 56, 176, 257, 65)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$files = FileSelectFolder("选择相应文件夹", @WorkingDir)
GUICtrlSetData($Input1, $files)
Case $Button2
If GUICtrlRead($Input1) = "" And GUICtrlRead($Input2) = "" Then
MsgBox("", "", "不允许为空啦")
ElseIf GUICtrlRead($Input3) = "" Then
MsgBox("", "", "请填写数量哦")
Else
_hui()
MsgBox("", "", "生成完毕")
EndIf
Case $MenuItem1
GUICtrlSetData($Input1, "")
Case $MenuItem3
Exit
EndSwitch
WEnd
Func _hui()
$style = GUICtrlRead($Combo1)
$way = GUICtrlRead($Input1)
$name = GUICtrlRead($Input2)
$number = GUICtrlRead($Input3)
$len = StringLen($number)
For $i = 1 To $number
_FileCreate($way & "\" & $name & "-" & StringFormat('%0' & $len & 'd', $i) & $style)
Next
EndFunc ;==>_hui
页:
[1]