AutoPepe Posted September 28, 2021 Share Posted September 28, 2021 I have a tree Y:\folder1\folder2\exp<year>\compo\file1.doc Y:\folder1\folder2\exp<year>\compo\file2.doc I need to copy two files from folder Y:\folder1\folder2\564.21\compo\file1.doc Y:\folder1\folder2\564.21\compo\file2.doc to many folders under the same tree Y:\folder1\folder2\exp<year> An utility to do this or similar tasks ? I need to establish conditions or rules like copy if the target folder is not empty or if the target folder is bigger than xx kb, etc Best regards Traducción AutoIt al Español. http://autoitespa.espanaforo.com/forum.htm . Visita el foro de AutoIt en español http://www.emesn.com/autoitforum/. I am a simple user, not a programmer. Link to comment Share on other sites More sharing options...
Subz Posted September 28, 2021 Share Posted September 28, 2021 (edited) You could use something like _FileListToArrayRec to capture the folders into an array and then use DirGetSize to determine folder conditions, example: #include <Array.au3> #include <File.au3> Global $g_sDir = @ScriptDir Global $g_iMaxSize = 1024 ;~ 1024kb Global $g_sFile1 = @ScriptDir & "\File1.doc" Global $g_sFile2 = @ScriptDir & "\File2.doc" Global $g_aFolders = _FileListToArrayRec($g_sDir, "*", 2, 0, 0, 2) If @error Then Exit MsgBox(4096, "Error", "No folders found") For $i = 1 To $g_aFolders[0] $aDirSize = DirGetSize($g_aFolders[$i], 1) ;~ Check if folder size is greater than 1024kb If Round($aDirSize[0]/1024, 2) >= $g_iMaxSize Then ConsoleWrite("Folder : " & $g_aFolders[$i] & @CRLF & "Size : " & Round($aDirSize[0]/1024, 2) & "kb" & @CRLF & "File Count : " & $aDirSize[1] & @CRLF & "Dir Count : " & $aDirSize[2] & @CRLF) ;~ FileCopy stuff here EndIf Next Edited September 28, 2021 by Subz Link to comment Share on other sites More sharing options...
junkew Posted September 28, 2021 Share Posted September 28, 2021 Powershell? * on 1 machine or more? FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
AutoPepe Posted September 28, 2021 Author Share Posted September 28, 2021 3 hours ago, junkew said: Powershell? * on 1 machine or more? only 1 machine. Is easy to manage powershell ? Best Regards Traducción AutoIt al Español. http://autoitespa.espanaforo.com/forum.htm . Visita el foro de AutoIt en español http://www.emesn.com/autoitforum/. I am a simple user, not a programmer. Link to comment Share on other sites More sharing options...
AutoPepe Posted September 28, 2021 Author Share Posted September 28, 2021 5 hours ago, Subz said: You could use something like _FileListToArrayRec to capture the folders into an array and then use DirGetSize to determine folder conditions, example: #include <Array.au3> #include <File.au3> Global $g_sDir = @ScriptDir Global $g_iMaxSize = 1024 ;~ 1024kb Global $g_sFile1 = @ScriptDir & "\File1.doc" Global $g_sFile2 = @ScriptDir & "\File2.doc" Global $g_aFolders = _FileListToArrayRec($g_sDir, "*", 2, 0, 0, 2) If @error Then Exit MsgBox(4096, "Error", "No folders found") For $i = 1 To $g_aFolders[0] $aDirSize = DirGetSize($g_aFolders[$i], 1) ;~ Check if folder size is greater than 1024kb If Round($aDirSize[0]/1024, 2) >= $g_iMaxSize Then ConsoleWrite("Folder : " & $g_aFolders[$i] & @CRLF & "Size : " & Round($aDirSize[0]/1024, 2) & "kb" & @CRLF & "File Count : " & $aDirSize[1] & @CRLF & "Dir Count : " & $aDirSize[2] & @CRLF) ;~ FileCopy stuff here EndIf Next I am not a programmer, so I would like to use a good script for this. configurable and versatile. Exist something done about this with a mild learning curve ? Traducción AutoIt al Español. http://autoitespa.espanaforo.com/forum.htm . Visita el foro de AutoIt en español http://www.emesn.com/autoitforum/. I am a simple user, not a programmer. Link to comment Share on other sites More sharing options...
junkew Posted September 28, 2021 Share Posted September 28, 2021 Backup your data as you start a learning curve Windows start button type ISE <enter> you are now in the simple IDE for powershell Copy paste below clear-host for ($year=2021; $year -le 2030; $year++) { $targetFolder="Y:\folder1\folder2\exp$year" write-host copying to $targetFolder if (Test-Path -Path $targetFolder) { if (@( Get-ChildItem $targetfolder).Count -ge 1) { write-host "There are files in $targetfolder" } else { $folderSize = ((Get-ChildItem . | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum) if ($foldersize -gt 100) { write-host "$targetfolder already has size $foldersize" } else { Copy-Item Y:\folder1\folder2\564.21\compo\file1.doc -destination $targetFolder Copy-Item Y:\folder1\folder2\564.21\compo\file2.doc -destination $targetFolder } } } else { "Path $targetFolder doesn't exist." } } Powershell has the benefit in general its on every machine around. Sometimes its easier then AutoIt sometimes its not. Both are very powerfull If you are not good in scripting you could create a bat file with excel and notepad but then no conditions Cell A1 you put Y:\folder1\folder2\exp<year>\compo\file1.doc Cell B1 you put Y:\folder1\folder2\exp<year>\compo\file2.doc Cell E1 type a formula="Copy " & B1 &" " & C1 Cell C1 you put "Y:\folder1\folder2\exp2020" Cell D1 type a formula="Copy " & A1 &" " & C1 You copy the line downwards for each year you need Copy column D data to notepad file copyit.bat Copy column E below the other data save it doubleclick the copyit.bat FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
ad777 Posted December 4, 2021 Share Posted December 4, 2021 On 9/28/2021 at 11:23 AM, AutoPepe said: I have a tree Y:\folder1\folder2\exp<year>\compo\file1.doc Y:\folder1\folder2\exp<year>\compo\file2.doc I need to copy two files from folder Y:\folder1\folder2\564.21\compo\file1.doc Y:\folder1\folder2\564.21\compo\file2.doc to many folders under the same tree Y:\folder1\folder2\exp<year> An utility to do this or similar tasks ? I need to establish conditions or rules like copy if the target folder is not empty or if the target folder is bigger than xx kb, etc Best regards #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> $folderSource = @ScriptDir & "\SevenFolder\" $folderDestin = @ScriptDir & "\Folders\" $year = "2000" $month = "11" $day = "01" Local $aFileList = _FileListToArray($folderSource,Default, Default, True) Local $aFileList2 = _FileListToArray($folderSource,"*") for $i = 0 to _ArrayMaxIndex($aFileList,0,1) Step 1 FileSetTime($aFileList[$i],$year&$month&$day,$FT_MODIFIED) DirMove($folderSource&$aFileList2[$i], $folderDestin & $aFileList2[$i]) Sleep(200) Next maybe this will help you. iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. 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