Bob1988 Posted October 31, 2017 Share Posted October 31, 2017 (edited) Hi , I have a folder, consists of several files and a database file (example.db) I am trying to write a script which can copy and at the same time change file's extensions for all files except the data base file. (example.db) How i can change the cod that i can chang file's extensions for all files except the data base file and rename the data base file from "exampel.db" to "exam.db" expandcollapse popup#include <GUIConstants.au3> #include <ComboConstants.au3> ; For GUICtrlCreateCombo #include <File.au3> ; For _FileListToArray Global $ComboExt, $Files ; For Find Files. $Form1 = GUICreate("file's copy & rename the Extension ", 618, 134, 193, 125) $Input_old = GUICtrlCreateInput("", 16, 16, 321, 21) $Datei = GUICtrlCreateButton("choose folder or file's ", 352, 16, 257, 25, 0) $Go = GUICtrlCreateButton("copy and rename ", 136, 88, 361, 41, 0) $Input_new = GUICtrlCreateInput("", 16, 48, 321, 21) $Button1 = GUICtrlCreateButton("new path or folder", 352, 48, 257, 25, 0) GUICtrlSetCursor($Datei, 0) ; ==> Added. GUICtrlSetCursor($Go, 0) ; ==> Added. GUICtrlSetCursor($Button1, 0) ; ==> Added. GUICtrlCreateLabel("New Extensions", 520, 80, 80, 20, 1) ; ==> Added. $ComboExt = GUICtrlCreateCombo("", 510, 100, 100, 50, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) ; ==> Added. GUICtrlSetData($ComboExt, ".jpg|.bmp|.png|.gif|", ".jpg") ; Choose The New Extensions Post File Move. ==> Added. GUICtrlSetCursor($ComboExt, 0) ; ==> Added. GUISetState(@SW_SHOW, $Form1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit(0) Case $Datei ;~ ;$path = FileOpenDialog("choose folder or file's", @ScriptDir, "Alle Dateien (*.*)") $path = FileSelectFolder("choose folder or file's", @ScriptDir) ; Correction / Added. GUICtrlSetData($Input_old, $path) Case $Button1 ;~ ;$path_new = FileSelectFolder ( "choose folder or file's", @ScriptDir, "Alle Dateien (*.*)") $path_new = FileSelectFolder("choose folder or file's", @ScriptDir, 1) ; Correction / Added. GUICtrlSetData($Input_new, $path_new) Case $Go GUICtrlSetState($Go, $GUI_DISABLE) GUICtrlSetState($Datei, $GUI_DISABLE) GUICtrlSetState($Button1, $GUI_DISABLE) GUICtrlSetData($Go, "wait!.") $Files = _FileListToArray($path , "*.*" , 1) ; 1 = Return Files Only. ==> Added. If Not @error Then _Copy($Files) ; ==> Added. EndSwitch WEnd Func _Copy($Files) ; Copies All Files to The New Location With The Extension You Have Chosen. Local $ReadExt = GUICtrlRead($ComboExt) For $i = 0 To UBound($Files)-1 FileCopy($path & "\" & $Files[$i], $path_new & "\" & StringRegExpReplace($Files[$i], ".*\\|\.[^.]*", "") & $ReadExt) Next GUICtrlSetState($Go, $GUI_ENABLE) GUICtrlSetState($Datei, $GUI_ENABLE) GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetData($Go, "End of copy") EndFunc Edited October 31, 2017 by Bob1988 Link to comment Share on other sites More sharing options...
mikell Posted October 31, 2017 Share Posted October 31, 2017 Just include a condition in your function For $i = 1 To $Files[0] If StringRight($Files[$i], 3) = ".db" Then .... Else .... EndIf Next Link to comment Share on other sites More sharing options...
Bob1988 Posted November 1, 2017 Author Share Posted November 1, 2017 Hi mikell, Thx for your help, it's working with copy how can i rename the file too, for exampel if the file "test1.db" to "test2.db". For $i = 1 To $Files[0] If StringRight($Files[$i], 3) = ".db" Then FileCopy($path & "\" & $Files[$i], $path_new & "\") ; how i can rename the file too, Else ...... Link to comment Share on other sites More sharing options...
SlackerAl Posted November 1, 2017 Share Posted November 1, 2017 Local $path = "D:\AutoIT\Programs\Test\" Local $Files[1] = ["test1.db"] FileMove($path & $Files[0], $path & "test2.db") Obviously, you can process $Files[0] anyway you like with string operations to generate a new name and use that instead of "test2.db" Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
Bob1988 Posted November 1, 2017 Author Share Posted November 1, 2017 thx for ur help, i didn't get it. i get an error. Link to comment Share on other sites More sharing options...
SlackerAl Posted November 1, 2017 Share Posted November 1, 2017 Those 3 lines work, I've just run them on my PC. What was your error? Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
Bob1988 Posted November 1, 2017 Author Share Posted November 1, 2017 (edited) I change the code like that, but i get the error --> Local $Files[0] = ["Test1.db"] Local ^ ERROR Func _Copy($Files) ; Local $ReadExt = GUICtrlRead($ComboExt) local $path = "C:\..."; with the right path Local $Files[1] = ["Test1.db"] ;For $i = 0 To UBound($Files)-1 For $i = 1 To $Files[0] If StringRight($Files[$i], 3) = ".db" then FileMove($path & $Files[0], $path & "Test2.db") Else Edited November 1, 2017 by Bob1988 change Link to comment Share on other sites More sharing options...
mikell Posted November 1, 2017 Share Posted November 1, 2017 (edited) Func _Copy($Files) Local $ReadExt = GUICtrlRead($ComboExt) For $i = 1 To $Files[0] ; $Files[0] contains the number of files ! If StringRight($Files[$i], 3) = ".db" then FileCopy($path & "\" & $Files[$i], $path_new & "\") ; first copy FileMove($path_new & "\" & $Files[$i], $path_new & "\" & "Test2.db") ; then rename Else ; copy other files EndIf Next EndFunc Edited November 1, 2017 by mikell Link to comment Share on other sites More sharing options...
Bob1988 Posted November 1, 2017 Author Share Posted November 1, 2017 oh Many thx Mikell it's working. thx alot. and thx to slackeral too Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now