YuChan Posted January 15, 2021 Share Posted January 15, 2021 (edited) Hello, I want select one file and rename I have this code : Global $inputNomTrajet = InputBox("Confirmation", "Entréz le nom du nouveau Trajet", "") Global $sMessage = "Select one .txt file" Global $sFileOpenDialog = FileOpenDialog($sMessage, @ScriptDir & "\", "Text files (*.txt)|Ini Files (*.ini)", $FD_FILEMUSTEXIST) $fileName = StringSplit ($sFileOpenDialog ,"\" ) $extention = StringSplit ($fileArrayValue [$fileArrayValue[0]],".") $oldFileName = $fileArrayValue [$fileArrayValue[0]] $newFileName = $inputNomTrajet & "." & $ext[$ext[0]] FileMove($oldFileName, $newFileName, 9) My problem is if it default folder it work but not work with other folder. Can you help me please ? Edited January 15, 2021 by YuChan Link to comment Share on other sites More sharing options...
Developers Jos Posted January 15, 2021 Developers Share Posted January 15, 2021 Use the full path to the file in stead of only the filename. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
rudi Posted January 15, 2021 Share Posted January 15, 2021 Hi. The script you posted even can't be run. In general, when a filemove doesn't work, usually either the file is opened (locked by some application), or you need NTFS rights either in the source folder and / or in the destination folder. CU, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
YuChan Posted January 15, 2021 Author Share Posted January 15, 2021 (edited) THX How to have second path file for : $newFileName Edited January 15, 2021 by YuChan Link to comment Share on other sites More sharing options...
rudi Posted January 15, 2021 Share Posted January 15, 2021 Pls. have a look into the help file example for the function _PathSplit() Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
YuChan Posted January 15, 2021 Author Share Posted January 15, 2021 Yes i have already search, but i don't know how to use. I have this in Google : Func _FileRename($file, $newname) Local $szDrive, $szDir, $szFName, $szExt _PathSplit($file, $szDrive, $szDir, $szFName, $szExt) Return FileMove($file, $szDrive & $szDir & $newname) EndFunc Link to comment Share on other sites More sharing options...
rudi Posted January 15, 2021 Share Posted January 15, 2021 (edited) Hi. #include <File.au3> #include <Debug.au3> ;FPFN = Full Path File Name with Ext. $FPFN="C:\temp\sub1\sub2\MySampleFile.txt" $NewFileName="NewFileName" Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" Enum $iFPFN,$iDrive,$iDir,$iFN,$iExt Local $aPathSplit = _PathSplit($FPFN, $sDrive, $sDir, $sFileName, $sExtension) _DebugArrayDisplay($aPathSplit) $aPathSplit[$iFN]=$NewFileName _DebugArrayDisplay($aPathSplit) ; or using RegExReplace $RegEx='(?i)(^.*\\)(.*?)(\.[^\.]*$)' ; (^.*\\) = get everything up to the final occurence of "\" ; (.*?) = get all what remains to be grabbed, when the next one ... ; (\.[^\.]*$) = grab everything to the end of string, starting with the last occurence of "." $RgExRepl="$1" & $NewFileName & "$3" $NewFPFN=StringRegExpReplace($FPFN,$RegEx,$RgExRepl) MsgBox(0, '', $NewFPFN) Edited January 15, 2021 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
YuChan Posted January 15, 2021 Author Share Posted January 15, 2021 THX all, problem solved Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 15, 2021 Moderators Share Posted January 15, 2021 YuChan, I sent you a PM yesterday - please read it. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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