Skip to main content
added 30 characters in body
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135
-- Begin script

on run
    SortFiles(POSIX path of (choose folder))
end run

on open (DroppedFolder)
    set DroppedFolder to POSIX path of DroppedFolder
    if text (length of text of DroppedFolder) of DroppedFolder is not "/" then quit
    SortFiles(DroppedFolder)
end open

on SortFiles(SortFolder)
    set AppleScript's text item delimiters to return
    set SortFolderContents to the text items of (do shell script "find '" & SortFolder & "' -type f")
    set FolderMakeList to {}
    repeat with ThisItem in SortFolderContents
        set ThisFile to ThisItem as string
        if ThisFile does not contain "/." then
            tell application "Finder"
                set DateString to text 1 thru 7 of ((creation date of ((POSIX file ThisFile) as alias)) as «class isot» as string)
                set ThisFilesFolder to SortFolder & text 1 thru 4 of DateString & "/"
                set ThisFilesSubfolder to ThisFilesFolder & text 1 thru 7 of DateString & "/"
            end tell
                if ThisFilesFolder is not in FolderMakeList then
                try
                    do shell script ("mkdir '" & ThisFilesFolder & "'")
                end try
                set FolderMakeList to FolderMakeList & ThisFilesFolder
            end if
            if ThisFilesSubfolder is not in FolderMakeList then
                try
                    do shell script ("mkdir '" & ThisFilesSubfolder & "'")
                end try
                set FolderMakeList to FolderMakeList & ThisFilesSubfolder
            end if
            try
                do shell script ("mv '" & ThisFile & "' '" & ThisFilesSubfolder & "'")
            end try
        end if
    end repeat
    return FolderMakeList
end SortFiles

-- End script
-- Begin script

on run
    SortFiles(POSIX path of (choose folder))
end run

on open (DroppedFolder)
    set DroppedFolder to POSIX path of DroppedFolder
    if text (length of text of DroppedFolder) of DroppedFolder is not "/" then quit
    SortFiles(DroppedFolder)
end open

on SortFiles(SortFolder)
    set AppleScript's text item delimiters to return
    set SortFolderContents to the text items of (do shell script "find '" & SortFolder & "' -type f")
    set FolderMakeList to {}
    repeat with ThisItem in SortFolderContents
        set ThisFile to ThisItem as string
        if ThisFile does not contain "/." then
            tell application "Finder"
                set DateString to text 1 thru 7 of ((creation date of ((POSIX file ThisFile) as alias)) as «class isot» as string)
                set ThisFilesFolder to SortFolder & text 1 thru 4 of DateString & "/"
                set ThisFilesSubfolder to ThisFilesFolder & text 1 thru 7 of DateString & "/"
            end tell
                if ThisFilesFolder is not in FolderMakeList then
            try
                do shell script ("mkdir '" & ThisFilesFolder & "'")
            end try
            set FolderMakeList to FolderMakeList & ThisFilesFolder
        end if
        if ThisFilesSubfolder is not in FolderMakeList then
            try
                do shell script ("mkdir '" & ThisFilesSubfolder & "'")
            end try
            set FolderMakeList to FolderMakeList & ThisFilesSubfolder
        end if
        try
            do shell script ("mv '" & ThisFile & "' '" & ThisFilesSubfolder & "'")
        end try
    end if
end repeat
return FolderMakeList
end SortFiles

-- End script
on run
    SortFiles(POSIX path of (choose folder))
end run

on open (DroppedFolder)
    set DroppedFolder to POSIX path of DroppedFolder
    if text (length of text of DroppedFolder) of DroppedFolder is not "/" then quit
    SortFiles(DroppedFolder)
end open

on SortFiles(SortFolder)
    set AppleScript's text item delimiters to return
    set SortFolderContents to the text items of (do shell script "find '" & SortFolder & "' -type f")
    set FolderMakeList to {}
    repeat with ThisItem in SortFolderContents
        set ThisFile to ThisItem as string
        if ThisFile does not contain "/." then
            tell application "Finder"
                set DateString to text 1 thru 7 of ((creation date of ((POSIX file ThisFile) as alias)) as «class isot» as string)
                set ThisFilesFolder to SortFolder & text 1 thru 4 of DateString & "/"
                set ThisFilesSubfolder to ThisFilesFolder & text 1 thru 7 of DateString & "/"
            end tell
            if ThisFilesFolder is not in FolderMakeList then
                try
                    do shell script ("mkdir '" & ThisFilesFolder & "'")
                end try
                set FolderMakeList to FolderMakeList & ThisFilesFolder
            end if
            if ThisFilesSubfolder is not in FolderMakeList then
                try
                    do shell script ("mkdir '" & ThisFilesSubfolder & "'")
                end try
                set FolderMakeList to FolderMakeList & ThisFilesSubfolder
            end if
            try
                do shell script ("mv '" & ThisFile & "' '" & ThisFilesSubfolder & "'")
            end try
        end if
    end repeat
    return FolderMakeList
end SortFiles
Edited code and how the current code displays the year and date
Source Link
2018 "YYYY"
├── 2018-01 "MM"
│   ├── 01 "DD"
│   └── 02
├── 02
│   ├── 01
│   └── 02
└── 03
    ├── 01
    └── 2018-02
-- Begin script

on run
    SortFiles(POSIX path of (choose folder))
end run

on open (DroppedFolder)
    set DroppedFolder to POSIX path of DroppedFolder
    if text (length of text of DroppedFolder) of DroppedFolder is not "/" then quit
    SortFiles(DroppedFolder)
end open

on SortFiles(SortFolder)
    set AppleScript's text item delimiters to return
    set SortFolderContents to the text items of (do shell script "find '" & SortFolder & "' -type f")
    set FolderMakeList to {}
    repeat with ThisItem in SortFolderContents
        set ThisFile to ThisItem as string
        if ThisFile does not contain "/." then
            tell application "Finder"
                set ThisFilesEpochDateString to dotext shell1 scriptthru "stat7 -fof \"%B\"((creation '"date &of ((POSIX file ThisFile) &as "'"alias)) as «class isot» as string)
                set ThisFilesFolder to SortFolder & (dotext shell1 scriptthru ("date4 -rof "DateString & ThisFilesEpoch"/"
                set ThisFilesSubfolder to ThisFilesFolder & "text \"+%b-%Y\""))1 thru 7 of DateString & "/"
            end tell
                if ThisFilesFolder is not in FolderMakeList then
                try
                    do shell script ("mkdir '" & ThisFilesFolder & "'")
                end try
                set FolderMakeList to FolderMakeList & ThisFilesFolder
        end if
       end if ThisFilesSubfolder is not in FolderMakeList then
            try
                do shell script ("mv"mkdir '" & ThisFileThisFilesSubfolder & "'"'")
 '" & ThisFilesFolder & "'")       end try
            set FolderMakeList to FolderMakeList & ThisFilesSubfolder
        end if
        try
            do shell script ("mv '" & ThisFile & "' '" & ThisFilesSubfolder & "'")
        end iftry
    end if
end repeat
return FolderMakeList
end SortFiles

-- End script
2018 "YYYY"
├── 01 "MM"
│   ├── 01 "DD"
│   └── 02
├── 02
│   ├── 01
│   └── 02
└── 03
    ├── 01
    └── 02
on run
    SortFiles(POSIX path of (choose folder))
end run

on open (DroppedFolder)
    set DroppedFolder to POSIX path of DroppedFolder
    if text (length of text of DroppedFolder) of DroppedFolder is not "/" then quit
    SortFiles(DroppedFolder)
end open

on SortFiles(SortFolder)
    set AppleScript's text item delimiters to return
    set SortFolderContents to the text items of (do shell script "find '" & SortFolder & "' -type f")
    set FolderMakeList to {}
    repeat with ThisItem in SortFolderContents
        set ThisFile to ThisItem as string
        if ThisFile does not contain "/." then
            set ThisFilesEpoch to do shell script "stat -f \"%B\" '" & ThisFile & "'"
            set ThisFilesFolder to SortFolder & (do shell script ("date -r " & ThisFilesEpoch & " \"+%b-%Y\"")) & "/"
            if ThisFilesFolder is not in FolderMakeList then
                try
                    do shell script ("mkdir '" & ThisFilesFolder & "'")
                end try
                set FolderMakeList to FolderMakeList & ThisFilesFolder
            end if
            try
                do shell script ("mv '" & ThisFile & "' '" & ThisFilesFolder & "'")
            end try
        end if
    end repeat
end SortFiles
2018 "YYYY"
├── 2018-01 "MM"
├── 2018-02
-- Begin script

on run
    SortFiles(POSIX path of (choose folder))
end run

on open (DroppedFolder)
    set DroppedFolder to POSIX path of DroppedFolder
    if text (length of text of DroppedFolder) of DroppedFolder is not "/" then quit
    SortFiles(DroppedFolder)
end open

on SortFiles(SortFolder)
    set AppleScript's text item delimiters to return
    set SortFolderContents to the text items of (do shell script "find '" & SortFolder & "' -type f")
    set FolderMakeList to {}
    repeat with ThisItem in SortFolderContents
        set ThisFile to ThisItem as string
        if ThisFile does not contain "/." then
            tell application "Finder"
                set DateString to text 1 thru 7 of ((creation date of ((POSIX file ThisFile) as alias)) as «class isot» as string)
                set ThisFilesFolder to SortFolder & text 1 thru 4 of DateString & "/"
                set ThisFilesSubfolder to ThisFilesFolder & text 1 thru 7 of DateString & "/"
            end tell
                if ThisFilesFolder is not in FolderMakeList then
            try
                do shell script ("mkdir '" & ThisFilesFolder & "'")
            end try
            set FolderMakeList to FolderMakeList & ThisFilesFolder
        end if
        if ThisFilesSubfolder is not in FolderMakeList then
            try
                do shell script ("mkdir '" & ThisFilesSubfolder & "'")
            end try
            set FolderMakeList to FolderMakeList & ThisFilesSubfolder
        end if
        try
            do shell script ("mv '" & ThisFile & "' '" & ThisFilesSubfolder & "'")
        end try
    end if
end repeat
return FolderMakeList
end SortFiles

-- End script
added 86 characters in body
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135

I have an AppleScript that has been written and it works as such, but I need to change the way it creates the folder structure. The script does the following

Folder is selected which contains files (in my case it will be photos)
It will then look at the pictures created date
create a YYYY (Year folder if not already created)
create a MM (Month folder if not already created)
create a DD (Day folder if not already created)
it will then move the photo into this folder and repeat for the next photo and repeat until completed.

The current folder structure is created as follows:

  • 2018 "YYYY"
  • 01 "MM"
    • 01 "DD"
      
    • 02
  • 02 Folder is selected which contains files (in my case it will be photos).
    • 01
    It will then look at the pictures created date.
    • 02
    Create a YYYY (Year folder if not already created).
  • 03Create a MM (Month folder if not already created).
    • 01
    Create a DD (Day folder if not already created).
    • 02
    It will then move the photo into this folder and repeat for the next photo and repeat until completed.

The current folder structure is created as follows:

2018 "YYYY"
├── 01 "MM"
│   ├── 01 "DD"
│   └── 02
├── 02
│   ├── 01
│   └── 02
└── 03
    ├── 01
    └── 02

This is great and works as designed, but I have changed my mind on how I would like the folders to look like,. I would like the following structure (which is almost the same just a different naming structure:

  • **2018
    • 001 January
      • 20180101
      • 20180102
    • 002 February
      • 20180201
      • 20180202
    • 003 March
      • 20180301
      • 20180302**
2018
├── 001 January
│   ├── 20180101
│   └── 20180102
├── 002 February
│   ├── 20180201
│   └── 20180202
└── 003 March
    ├── 20180301
    └── 20180302

Now I have tried to work out where the script generates this but I have failed, so nonow I am turning to this great place for some help.

I have an AppleScript that has been written and it works as such but I need to change the way it creates the folder structure. The script does the following

Folder is selected which contains files (in my case it will be photos)
It will then look at the pictures created date
create a YYYY (Year folder if not already created)
create a MM (Month folder if not already created)
create a DD (Day folder if not already created)
it will then move the photo into this folder and repeat for the next photo and repeat until completed.

The current folder structure is created as follows

  • 2018 "YYYY"
  • 01 "MM"
    • 01 "DD"
      
    • 02
  • 02
    • 01
    • 02
  • 03
    • 01
    • 02

This is great and works as designed but I have changed my mind on how I would like the folders to look like, I would like the following structure (which is almost the same just a different naming structure

  • **2018
    • 001 January
      • 20180101
      • 20180102
    • 002 February
      • 20180201
      • 20180202
    • 003 March
      • 20180301
      • 20180302**

Now I have tried to work out where the script generates this but I have failed so no I am turning to this great place for some help

I have an AppleScript that has been written and it works as such, but I need to change the way it creates the folder structure. The script does the following:

  • Folder is selected which contains files (in my case it will be photos).
  • It will then look at the pictures created date.
  • Create a YYYY (Year folder if not already created).
  • Create a MM (Month folder if not already created).
  • Create a DD (Day folder if not already created).
  • It will then move the photo into this folder and repeat for the next photo and repeat until completed.

The current folder structure is created as follows:

2018 "YYYY"
├── 01 "MM"
│   ├── 01 "DD"
│   └── 02
├── 02
│   ├── 01
│   └── 02
└── 03
    ├── 01
    └── 02

This is great and works as designed, but I have changed my mind on how I would like the folders to look like. I would like the following structure (which is almost the same just a different naming structure:

2018
├── 001 January
│   ├── 20180101
│   └── 20180102
├── 002 February
│   ├── 20180201
│   └── 20180202
└── 003 March
    ├── 20180301
    └── 20180302

Now I have tried to work out where the script generates this but I have failed, so now I am turning to this great place for some help.

edited title to be specific about actual problem
Source Link
grg
  • 205.5k
  • 45
  • 364
  • 495
Loading
Source Link
Loading