Jump to content
Sign in to follow this  
augustspies

create folders day of wk in letters and move folders into it

Recommended Posts

augustspies

hey forum,

I currently have a source folder with about 50 sub-folders in it.

What I am trying to do is create a destination folder w/ each day of the week in letters in it

then move 6 sub-folders from the source folder into each day of the week folder

me and a friend put together the script below however we didn't know how to do the above step.

what the script does below, is takes files within the source folder, creates # of main folders specified,

puts # of sub folders specified into the main folders and copies the source files into each sub folder.

any help with what i'm trying to do would be greatly appreciated. i'm thinking a switch is needed of some sort to change the days of wk to letters but i'm not really sure.

thanks in advance for your time

#Include <File.au3>

$sourceFolder = @ScriptDir & "\source"
$destinationFolder = @ScriptDir & "\folders"
$mainFolderPrefix = "main_" & @WDAY
$subFolderPrefix = ""

$howmanyMain = 6
$howmanySubs = 6

$mainFolderCount = 0
$subFolderCount = 0

For $i = 1 to $howmanyMain Step 1
    $newfolder = $destinationFolder & "\" & $mainFolderPrefix & $i
    DirCreate($newfolder)
    $mainFolderCount+=1
    For $x = 1 to $howmanySubs step 1
        $subFolder = $newFolder & "\" & $subFolderPrefix & $x
        DirCreate($subFolder)

        ; copy the files in source folder into the newly created sub folder
        FileCopy($sourceFolder, $subFolder, 1)

        $subFolderCount+=1
    Next
Next

MsgBox(0,"","Created " & $mainFolderCount & " main folders and " & $subFolderCount & " subfolders total.");

Share this post


Link to post
Share on other sites
MrMitchell

Do an #include <Date.au3> then Check the function _DateDayOfWeek

Full description here. I think that's what you need, yes?

Edited by MrMitchell

Share this post


Link to post
Share on other sites
augustspies

Do an #include <Date.au3> then Check the function _DateDayOfWeek

Full description here. I think that's what you need, yes?

hey mrmitchell, thanks for the reply - I just gave your suggestion a try and it does create the folder for the day.

However i think my explanation i gave was wrong and i apologize for the confusion. I would like to create 7 folders each named to the day of the week ie folder 1: monday, folder 2: tuesday etc

Share this post


Link to post
Share on other sites
MrMitchell

Just a simple For loop from 1 to 7 to generate all the days

#include <Date.au3>

For $i = 1 to 7
    $sDayofWeek = _DateDayOfWeek($i)
    ConsoleWrite($sDayofWeek & @CRLF)
    ;DirCreate(blah blah blah & '\' & $sDayofWeek)
Next

Or since you need all of them, you can avoid using Date.au3 and go this route:

Dim $aDays[7] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

For $each In $aDays
    ConsoleWrite($each & @CRLF)
Next
Edited by MrMitchell

Share this post


Link to post
Share on other sites
augustspies

Or since you need all of them, you can avoid using Date.au3 and go this route:

Dim $aDays[7] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

For $each In $aDays
    ConsoleWrite($each & @CRLF)
Next

Great, This 2nd way worked great :) Thank you MrMitchell.

For the 2nd part of my question. I used dircreate to create 6 sub folders in each day of the week folder created.

How would I take the source folder w/ 50 sub-folders and move 6 of them into each day of the week folder for a total of 42 folders moved?

Share this post


Link to post
Share on other sites
MrMitchell

Great, This 2nd way worked great :) Thank you MrMitchell.

For the 2nd part of my question. I used dircreate to create 6 sub folders in each day of the week folder created.

How would I take the source folder w/ 50 sub-folders and move 6 of them into each day of the week folder for a total of 42 folders moved?

Well I can't imagine you would want to move 6 of them into each day's folder, since a move deletes your source folder. So use DirCopy()

Share this post


Link to post
Share on other sites
Malkey

Try this.

#include <File.au3>
;#include <Array.au3>

;------- Create test directory with subdirectories ----------
Local $sourceFolder = "C:\TestDir", $File = 0
If FileExists($sourceFolder & "\Dir01\File1.txt") = 0 Then
    DirCreate($sourceFolder)
    For $i = 1 To 42
        DirCreate($sourceFolder & "\Dir" & StringRight("0" & $i, 2))
        $File += 1
        _FileCreate($sourceFolder & "\Dir" & StringRight("0" & $i, 2) & "\File" & $File & ".txt")
        $File += 1
        _FileCreate($sourceFolder & "\Dir" & StringRight("0" & $i, 2) & "\File" & $File & ".txt")
    Next
EndIf
MsgBox(0, "Pause", 'You may now check the existence of "C:\TestDir" and its subdirectories.' & @CRLF & _
        "And, remember to REFRESH Folders if directory is not visible." & @CRLF & @CRLF & _
        "Press button to continue")
;-------> End of Create test directory with subdirectories ----------

; ----- Move directories -----------------------
Local $aDays[8] = [7, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
Local $sourceFolder = "C:\TestDir"
Local $destinationFolder = "C:\TestDirNew"
Local $howmanySubs = 6
Local $aDirList = _FileListToArray($sourceFolder, "*", 2) ; Directories only.
;_ArrayDisplay($aDirList)

For $i = 1 To 7
    DirCreate($destinationFolder & "\" & $aDays[$i])
    For $SubDirs = ($howmanySubs * ($i - 1)) To ($howmanySubs * $i) - 1
        $SrcSubDir = $sourceFolder & "\" & $aDirList[$SubDirs + 1]
        $DestSubDir = $destinationFolder & "\" & $aDays[$i] & "\" & $aDirList[$SubDirs + 1]
        DirMove($SrcSubDir, $DestSubDir)
    Next
Next

MsgBox(0, "Check Files before Finish", "Directories Moved - Check before button is pressed.")

DirRemove($sourceFolder, 1)
DirRemove($destinationFolder, 1)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×