bboychua Posted April 10, 2020 Posted April 10, 2020 Hi everyone, I am very new to AutoIt, still learning on it. I have made myself a project. I am trying to group the files with the same last 6 digits into a file. For example, files end with 223344 will move/copy to a folder, while files end with 112233 will move/copy to another folder. Is it possible?
Moderators Melba23 Posted April 10, 2020 Moderators Posted April 10, 2020 Moved to the appropriate forum. Moderation Team 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
bboychua Posted April 10, 2020 Author Posted April 10, 2020 Hi everyone, I am very new to AutoIt, still learning on it. I have made myself a project. I am trying to group the files with the same last 6 digits into a file.For example, files end with 223344 will move/copy to a folder, while files end with 112233 will move/copy to another folder. Is it possible?
Moderators Melba23 Posted April 10, 2020 Moderators Posted April 10, 2020 (edited) bboychua, Welcome to the AutoIt forums. I would read the files into an array (_FileListToArray) and then loop through the array (For...Next). For each file you could look at the final 6 characters (_StringRight) and then, depending on the result (Switch), move the file to the folder you wish (FileMove). Try and code something yourself using the functions I mentioned - you know where we are if you run into problems. M23 Edited April 10, 2020 by Melba23 Blushes! 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
Moderators Melba23 Posted April 10, 2020 Moderators Posted April 10, 2020 bboychua, Please only post in ONE forum at a time - threads merged. 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
bboychua Posted April 10, 2020 Author Posted April 10, 2020 thank you @Melba23, sorry for posted twice.
Musashi Posted April 10, 2020 Posted April 10, 2020 24 minutes ago, Melba23 said: I would read the files into an array (_FileReadToArray) and then loop through the array (For...Next). I assume you mean _FileListToArray . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Moderators Melba23 Posted April 10, 2020 Moderators Posted April 10, 2020 Musashi, Ooops! Changed above. Thanks. 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
bboychua Posted April 10, 2020 Author Posted April 10, 2020 Hi, I tried to move all files into 1 folder, but fail... It doesn't create a file folder.
Nine Posted April 10, 2020 Posted April 10, 2020 To start you off : #include <File.au3> Local $aFile = _FileListToArray (@ScriptDir, "*.txt", $FLTA_FILES) _ArrayDisplay ($aFile) Local $sDir For $i = 1 To $aFile[0] $sDir = StringTrimRight(StringRight($aFile[$i],10),4) FileCopy ($aFile[$i],@ScriptDir & "\" & $sDir & "\*.*", $FC_OVERWRITE + $FC_CREATEPATH) ConsoleWrite ($sDir & "/" & $aFile[$i] & "/" & @error & @CRLF) Next And please use this tool, when you post code. bboychua 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
Musashi Posted April 10, 2020 Posted April 10, 2020 2 hours ago, bboychua said: I am trying to group the files with the same last 6 digits into a file. I suppose, you want to copy/move files ending with the same 6 digits in the name to another folder (not to a file). Here is a variation that checks the last 6 digits as well (it can also be solved completely with a regex (without PathSplit). #include <File.au3> Global $g_aFilelist = _FileListToArrayRec(@ScriptDir, "*.txt", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) Global $g_iLastDigits, $g_aTargetDir, $g_aPathSplit, $g_sDrive = "", $g_sDir = "", $g_sFileName = "", $g_sExtension = "" $g_aTargetDir = @ScriptDir & "\home\" $g_iLastDigits = "123456" ; last 6 digits of the filename For $iPos = 1 To $g_aFilelist[0] $g_aPathSplit = _PathSplit($g_aFilelist[$iPos], $g_sDrive, $g_sDir, $g_sFileName, $g_sExtension) If StringRegExp($g_sFileName, "(?i)^.*?" & $g_iLastDigits & "$") Then FileCopy($g_aFilelist[$iPos], $g_aTargetDir, BitOR($FC_OVERWRITE, $FC_CREATEPATH)) ConsoleWrite("+ File matches : " & $g_aFilelist[$iPos] & " ==> Copy : ERROR = " & @error & @CRLF) Else ConsoleWrite("! File not matches : " & $g_aFilelist[$iPos] & @CRLF) EndIf Next "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
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