Sort to subfolders based on last three letters of file

I am working on a script i found that will take the contents of a folder and seperate them into sub folders based on the last three characters of the file name. They are named by user and month for example: Sam_Jan.xlsx. Here is what i have so far:
property nameList : {"_Jan", ""}
property destFoldersPath : {"/Users/ba/Desktop/DWI monthly/jan", ""}
on adding folder items to masterFolder after receiving these_items
repeat with tFile in these_items
set destFolder to my check_end_of_Name(tFile as string)
if destFolder is not "" then
tell application "Finder" to move tFile to destFolder with replacing
end if
end repeat
end adding folder items to
on check_end_of_Name(t)
set tc to count nameList
repeat with i from 1 to tc
if t ends with (item i of nameList) then return (POSIX file (item i of destFoldersPath)) as alias
end repeat
return ""
end check_end_of_Name
nothing happens when i run the script. my experience with applescript is pretty basic, but i feel like i need to put the source file in there somewhere but im not sure. the source file is a folder on my desktop called DWI Annual Report. Thanks for your help.

samiam2356 wrote:
I am working on a script i found that will take the contents of a folder and seperate them into sub folders based on the last three characters of the file name. They are named by user and month for example: Sam_Jan.xlsx.
I prefer to use a bash script for something like this.
This script will look in the Folder "DWI monthly" on your Desktop.
It will look for the last 3 char in all files, and move to a Sub-Folder in "DWI monthly" with those 3 characters (i.e. Jan)  If the Sub-Folder does not exist, then nothing is done.  
If the file already exists in the Sub-Folder, it will be replaced.
This uses a do shell script , so this can be run in Applescript
do shell script "
for f in \"$HOME/Desktop/DWI monthly/\"*
do
    if [ ! -d \"$f\" ]; then
        x=\"${f%%.*}\"
        i=$((${#x}-3))
        if [  -d \"$HOME/Desktop/DWI monthly/${f:$i:3}\" ]; then
            mv \"$f\" \"$HOME/Desktop/DWI monthly/${f:$i:3}\"
        fi
    fi
done"
(BTW, your Applescript is a Folder Action (on adding folder items to), is that what you want?)

Similar Messages

  • Vertical Lines for last Three Records

    hi,
    Guys
    I have dev the smart form... in my final itab ive got 23 records.. i need last three records much hve  vertical lines..
    how to do it...Plz let me know
    Regards

    Hi,
    Good day swarna
    How r u? Hope ur doing well. A small favour to me. 
    A small problem in alv report. plz advice me. I done alv report but client has changed the requirement.
    He Needs the report first record displays Item total. and then displays iteams list. so. i worte the code as below as. but its not working.
    My itab data looks like below.
    Mtpos    Ktgrm_d   Des  Value
    Znam     bomag     xyz     10
    Znam      bomag    fdfj       10
    Nam       bomag    fjfff        20
    znam     volvo        fdkfjkd  40
    nam       volvo       erje       30
    in my report i  need to disply based on the ktgrm_d which is part name. No need to display the mt pos.
    Iam doing the at new also based on ktgrm_d. so report should be like
      Ktgrm_d         Des     Value
      Bomag                        40         "total values"
      Bomag                        10        "these are items
      Bomag                        10
      Bomag                        20
      volvo                           70         "total values
      Volvo                           40
      volvo                            30
    Can you guide me plz. send me smaple code if uve time.
         CLEAR: lwa_out5.
      REFRESH:  lt_machine_sales4.
      DATA: lwa_out1 type  zsalessm.
    SORT lt_machine_sales BY ktgrm_d ascending.
      LOOP AT lt_machine_sales INTO lwa_out5.
        lwa_out1 = lwa_out5.
        AT NEW ktgrm_d.
          SUM.
          lwa_out5-sales_qty = lwa_out5-sales_qty * -1.
          lwa_out5-act_sales_p = lwa_out5-act_sales_p * -1.
          lwa_out5-act_cos_p = lwa_out5-act_cos_p * -1.
          lwa_out5-act_gross_p = lwa_out5-act_gross_p * -1.
          lwa_out5-act_gross_perc_P = lwa_out5-act_gross_perc_p * -1.
          lwa_out5-netwr      = lwa_out5-netwr * -1.
          APPEND lwa_out5 TO lt_machine_sales4.
          clear:lwa_out5.
         ENDAT.
         Append lwa_out1 To lt_machine_sales4.
         clear:lwa_out1.
      ENDLOOP.
    Regards

  • Last three month data

    Hi,
    Requirement:
    Want to show last three months data dynamicaly based month value seleted in prompt. ex: When Septemper is selected report should show, Sep, Aug, Jul
    tried using ago function but i want to use three measure columns. So is there way using single measure column and achieving.
    Thanks,
    Satheesh

    Satheesh Kumar  wrote:
    Hi,
    Requirement:
    Want to show last three months data dynamicaly based month value seleted in prompt. ex: When Septemper is selected report should show, Sep, Aug, Jul
    tried using ago function but i want to use three measure columns. So is there way using single measure column and achieving.
    Thanks,
    SatheeshSatheesh, I have a question for you. It is the same as the comment left on the article in the link that @user gave you. Like that link -- which doesn't work for all scenarios, how are you accounting for say the month of January? Without a "year" included, you cannot always "subtract 3" to get "3 months ago." Does "month" always correspond to the current year?
    Finally, what are the values of the column the filter is to be applied? All these are important to know if you want help on this. Try again. Thanks.

  • Issue with form based Authentication in three tier sharepoint 2013 environment.

    Hi,
    We are facing issue with form based Authentication in three tier environment.
    We are able to add users to the database and in SharePoint.
    But we are not able to login with created users.
    In single tier everything working fine
    Please help , Its urgent ... Thanks in advance.
    Regards,
    Hari
    Regards, Hari

    if the environments match, then it sounds like a kerberos double-hop issue
    Scott Brickey
    MCTS, MCPD, MCITP
    www.sbrickey.com
    Strategic Data Systems - for all your SharePoint needs

  • Loading Last three days of delta records in Production Server

    Hi
    I have a Process Chain in BI-Production Server which runs dailiy  and loads the delta records dailiy  . I have 'Custom DataSource' which loads the data from QM-Tables .
    My Process Chain is failied due to the "Caller 09 Error for the datasource". So now i transported that datasource from R/3-Dev To R/3-Production and replicated into BI-Production Server .
    So how can i load the delta records of last three days . I mean , how can i scehdule the last three days of delta updated records .
    pls let me  know
    regards
    Kumar

    Remove the failed request. Repeat the delta. This will upload previous failed request
    Repeat the delta again with infopackage selection for 3 days

  • Run process chain on last three days of the month

    Hello
    I need to run process chain on last three days of the month. For example , It should run on 28, 29 and 30th dates of June.
    There is no option to put a code in the start process of the process chain.
    I can run it every day and put a code in the infopackage/DTP so that empty load (0 records) will be done on other days.
    This doesnt sound as a good option.
    Do u know any other options?

    Hi
    See the code and details how to do it, and change the code as per your requirement.
    http://wiki.sdn.sap.com/wiki/display/profile/Surendra+Reddy
    Triggering  the Process Chains at Particular Date using Events
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/business-intelligence/s-u/triggering%20%20the%20process%20chains%20at%20particular%20date%20using%20events.pdf
    BI-ABAP (Trigger Process Chains on evry month 3rd and 4th day).
    https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=81428842 
    Thanks
    Reddy

  • Last two letters do not print

    I have a formula column cf_1 in my report 'purchase order'which actually converts the numeric value of a summary column 'AMOUNT' to the character form.This is to show the amount both in words&numerical figures.Next to cf_1 I have attached a text string 'only' and the same has been anchored to cf_1.The horizontal elasticity property of cf_1 is set to 'variable'.Ideally at run time, the formula coulmn with the text string,for example, should read 'ONE HUNDERD ONLY'.But it always omits the last two letters of cf_1 and instead gives the output like this-'ONE HUNDR ONLY'.Can anybody tell me as to how this problem can be fixed?
    My Oracle version 8i& Reports 6i
    Thank you in advance
    Jay

    This is possibly to do with the "width" of the formula column - it's probably set to "10" and is therefore truncated at this point.
    Another way of creating your output, rather than having variable sized fields and anchors, is to just have a single boilerplate object. You can reference the formula column directly in the boilerplate object and insert any surrounding text: eg: "&<cf_1> only". This will give you the output you want without requiring the field and is simpler to debug and manage.

  • Truncating last three characters in Mainfram GDG dataset.

    Hi Folks,
    I had developed a scenario IDOC - > XI -> File and this file is generated on Mainframe system as a GDG dataset . I was able to generate the file but last three characters are getting truncated for each record in the file(dataset). From XI we are sending them correctly but on Mainframe system these last three characters are getting truncated.
    For generating a file i.e. GDG dataset  on Mainframe system I am using Fixed field lengths, my record length is of 254, and I am not missing any of the field length in fixed field lengths.
    When I use BINARY format I am able to get the complete record but in TEXT format I am unable to have the last three characters in a record.
    Is there any record size restrictions to 255 in Mainframe GDG dataset while generating the dataset ? If so, how can we overcome this situation?
    Please help me....
    Thanks,
    Vijay.

    Answered by my self...
    To over come this issue we have to increase the size of the Mainframe GDG dataset. To increase the size of dataset
    File Receiver Communication Channel>Module
    Processing Sequence
    1     FTPUtility     Local Enterprise Bean     1
    2     FTPUtility     Local Enterprise Bean     2
    Module Configuration
    1     AllocationParameters     LRECL=300 BLKSIZE=30000 RECFM=VB RETPD=60
    1     Mode                     preallocate
    2     Mode                     move
    2     NewDataset     'File Name'
    And make sure the file name in Module and Parameters are different.
    Thanks,
    Vijay.

  • How to sort a collection based on their date?

    how do i sort a collection based on their respective dates which are in Calendar format?

    this is my codes
    /** This class is use to sort the call list base on their date
    import java.util.*;
    public class a implements Comparator
         /** compare the objects base on their types
         *     @obj1 the first object to be compared
         *     @obj2 the second object to compare with the first object
         public int compare(Object obj1, Object obj2)
         if (obj1 == obj2)
              return 0;
         if (obj1 == null || obj2 == null)
              return 0;
         if (!(obj1 instanceof Call) || !(obj2 instanceof Call))
              return 0;
         Call lhs = (Call) obj1;
         Call rhs = (Call) obj2;
         int s = lhs.getDate().compareTo(rhs.getDate());
         if (s != 0)     
              return s;
         return 1;
    this is the error
    a.java:21: cannot resolve symbol
    symbol : method compareTo (java.util.Calendar)
    location: class java.util.Calendar
         int s = lhs.getDate().compareTo(rhs.getDate());

  • IPhone 4S using 3G in the background,causing huge battery loss. From last three days I'm finding my phone switched off in the morning when I wake up. Please Help

    iPhone 4S using 3G in the background,causing huge battery loss. From last three days I'm finding my phone switched off in the morning when I wake up. Please Help

    Maybe you hit the power button for 5 sec while you were asleap?
    And what do you want to say us with:
    Abhijeet Gupta wrote:
    iPhone 4S using 3G in the background,causing huge battery loss.

  • TS1718 I have purchased two complete albums in the last three weeks, old Bob Seger and new Maroone 5, both have the same issue, only a few songs will play and will skip over the rest of the songs on IPod and on computer????

    I have purchased two complete albums in the last three weeks, old Bob Seger and new Maroone 5, both have the same issue, only a few songs will play and will skip over the rest of the songs on IPod and on computer????

    Assuming you are in a region where you are allowed to redownload your past music purchases, delete the corrupt tracks from the music section of your iTunes library, close & then reopen iTunes, go to the iTunes Store home page, click the Purchased link from the Quick Links section in the right-hand column, then select Music and Not on this computer. You should find download links for your tracks there.
    While downloading select Downloads in the left-hand column and make sure Allow Simultaneous Downloads is unchecked. This seems to help with partial downloads...
    If the problem persists, or that facility is not yet available in your region, contact the iTunes Store support staff through the "Report a problem" links in your account history, or via Contact Support.
    See also:
    HT5085 - iTunes in the Cloud and iTunes Match Availability
    HT2519 - Downloading past purchases from the App Store, iBookstore, and iTunes Store
    tt2

  • I have produced (7) hard cover iPhoto books in the last three years and would like to create a using a custom photo arrangement if possible.

    I have produced (7) hard cover iPhoto books in the last three years using several of the provided templates.  I would like to create a photo book using a custom photo arrangement if possible.  Is it possible to create a custom photo book?

    No - you can create custom pages in other software and use them
    Using iPhoto you are limited to the themes adn layouts offered
    LN

  • HT4859 Can you restore an app prior to the last three backups? If so, how?

    I have an app that's frozen up at the logo screen. I did a restore of the iPad, but it wouldn't give me an option before the last three. everything restored just fine; however, found that i really need to go back about a week. I don't have that option on my iPad. Can this be done via computer? Any suggestions? I have iPad with retina, have the latest updates, etc.

    iCloud only retains your last three iCloud backups.  Older backups are no longer available.  You could check to see if you have an older one on your computer by opening iTunes, going to Preferences>Devices and checking the Backups list.  If not, there's no way to restore it.

  • Please tell me that I can sort my contacts by "Company,Last Name"

    I just purchased a Treo 650
    I depend on being able to sort my Contacts by "Company, Last Name" where is this preference feature on the Treo 650 in Contacts.
    If this is not possible the Treo becomes useless to me.
    Please tell me I am missing something.
    Post relates to: Treo 650 (Cingular)

    Yes you can "sort" by Company Name BUT....you cannot "search" by Company Name -- when you try a search it just keeps searching in the "name" fields and does NOT return a Company Name.
    --if you know the name of the person you want to call (which you more than likely will) then searching by name is fine
    but
    --if you can't remember their name (or there are multiple names) but want to look up the company and then scroll through list of names at that company -- forget it -- I can't make it work.

  • Sorting an ArrayList based on the value of a field in one of the objects.

    Hi,
    I have the following problem:
    A server app returns an array list of simple objects with a bunch of fields.
    One of these fields is an int.
    How do I go about sorting the list based on the size of the int?
    Thanks in advance!

    Thanks a lot.
    The Comparator solution is actually ridiculously simple.....
    public class MyComparator implements Comparator {
    public int compare(Object o1, Object o2) {
         if (Integer.parseInt(((ZMData)o1).getAantalposts())>Integer.parseInt(((ZMData)o2).getAantalposts())) {
              return 1;     
         if (Integer.parseInt(((ZMData)o1).getAantalposts())<Integer.parseInt(((ZMData)o2).getAantalposts())) {
              return -1;     
         return 0;
    }Thanks again.

Maybe you are looking for