Script or Automator to reorder text in file/folder name

Hello,
Similar to this discussion: https://discussions.apple.com/thread/2632228, I would like to reorder a large number of folder names. Currently, they are set up as follows:
"Name - Year" and would like to change them all to "Year - Name". I have over 200 folders named in this format so I need to find either a way to do this via the automator or via a script. So far I can't find what I need in the Automator. Any ideas? Thank you

try this:
set folderList to choose folder with multiple selections allowed
tell application "System Events"
          repeat with thisFolder in folderList
                    set folderName to name of thisFolder
  -- assumes none of the folders have extensions, or anything aside from "Name - Year", and that there are no spaces inside the name or year
  -- it can be generalized to deal with that, if needed
                    set {oldTID, my text item delimiters} to {my text item delimiters, {" ", "-"}}
                    tell folderName
                              set {n, d} to {first text item, last text item}
                    end tell
                    set my text item delimiters to oldTID
                    set name of thisFolder to d & " - " & n
          end repeat
end tell

Similar Messages

  • Script for Automator to reorder text in file/folder name.

    I have a folder full of pictures named by their first and last names. I need them to be renamed by listing them by last name first, first name last in order to get them alphabatized properly. Anybody out there have a nice Automator script for me to make this happen? I'm new.
    Looking for it to look like this:
    Brown, John

    Try this (should work for "John H Smith" --> "Smith John H" as well):
    The Run Shell Script Action is:
    for f in "$@"
    do
        basename=${f##*/}
        path=${f%/*}
        ext=${f##*.}
        name=${basename%.*}
        if [[ "$name" =~ \  ]]; then
            fname=${name% *}
            lname=${name##* }
            name="$lname $fname"
            mv "$f" "$path/$name.$ext"
        fi
    done
    If you want a comma, then change: name="$lname $fname" to name="$lname, $fname"
    As with all scripts, back-up the files before running

  • A Few SEO Questions: Alt="" text and file/folder names.

    I've been reading about the Dark Art of SEO and frankly, a lot of it is more confusing than I anticipated.  Anyway, I'll summarise a bit here.I have read that:
    File/folder names are better with meaningful words and hyphenated words.  so DCM000123.jpg in a folder called galimg would be better as: /gallery-images/painting-title-here.jpg
    Alt="" text can add to the content of your pages.
    My thinking underneath this relates to a gallery site I built with around 200 individual paintings in it.  So the site has a lot of content but not a lot of text.  I wonder if I should start trawling through all of this to change the file names and folders and add alt="" text more meaningfully to help with SEO?
    So if my thinking is OK, here are the questions.
    How would you put the alt="" text on individual images?  I imagine that it should just be a straight-forward, what-you-see description?  But there are a few other options.  Suppose I have an image that the artist has titled, "Cattle on a Hill" and it's an oil on canvas.  I could make that into,
    alt="Oil on Canvas: Cattle on a Hill" or
    alt="Cattle on a Hill" or
    alt="A group of cows grazing in pasture under moonlight." or
    Suppose I have 20 images in a portrait gallery:
    alt="Portrait.  Oil on canvas: Joe Bloggs" or
    alt="Portrait.  Joe Bloggs" or
    alt="Man with grey hair wearing a blue shirt sitting on a bench" or
    alt="Portrait painting.  Oil on canvas. Joe Bloggs: Man with gray hair wearing a blue shirt sitting on a bench"
    The second part of the question also includes the problem that if I have 20 images in a single gallery page and I put "Portrait painting" in each alt="" text is that going to look like key word stuffing?
    Now on to the file name thing.  Should the file names be portrait-painting-01 and so on or should they be Cattle-on-hill or what?
    Final question: am I making too much of all this?
    Thanks
    Martin

    First of all, stay away from spaces in file names AT ALL COST.
    The examples you cited would look like:
    alt="Oil%20on%20Canvas:%20Cattle%20on%20a%20Hill" or
    alt="Cattle%20on%20a%20Hill" or
    alt="A%20group%20of%20cows%20grazing%20in%20pasture%20under%20moonlight."
    to an SE crawler.
    If you really want effective picutres, use Photoshop or Fireworks to embed metadata and THEN add them to your site.
    Alt tags means the text that would appear if the image didn't for some reason. It also helps with accessibility for visually impaired viewers who use plug-ins to allow their browser to "speak" the images to them when the page loads.
    <img src="img/example-1.jpg" width="128" height="160" alt="example-1.jpg" />
    Above is an example of how to add alt text. Dreamweaver actually loads the alt tag automatically unless you've turned it off somehow.
    Either put the info in the Alt box in the properties panel, or in code view, add it between the quotes.
    To the second part of your question, Alt tags are meant for SEO with the images only (Like when you search for images of a certain name or containing certain tags)
    and really have little effect on the page SEO itself. For that type of optimization you want Keywords, and Descriptors in the <head> portion of the
    individual page:
    <meta name="google-site-verification" content="Optimizer code would go here" />
    <meta name="Description" content="Page name, site name, business name, location, phone number, etc. goes here"/>
    <meta name="Keywords" content="Restaurant, Sports bar, Catering, Hotel, Gallery, Car Dealer, Exterminator or whatever describes the site and page as well as content of the pages"/>
    <meta name="author" content="your name here"/>
    <meta name="robots" content="index, follow"/> (This tells search engine crawlers to index this page and each one you add it to,  and follow them site wide)
    <meta name="revisit-after" content="7 days"/> (This tells the crawler when to revisit for updates after it has indexed the site)
    To your last question. No, you're not making too big a deal out of it, if you're talking about exposure for a business. If it's a personal gallery of your favorite vacation pictures? You just might be.

  • Keyboard not working (sometimes) when attempting to change file/folder name

    Every now and then, my keyboard doesn't seem to work when I'm trying to change the name of file or folder. I can't isolate any particular context when this occurs. When it happens, the keyboard works fine in other applications.
    Any ideas on why this happens?

    Here's a description of what happens. Let's say I want to change the name of a file or folder on my desktop. I click the item, then the name, and the name becomes editable. Every now and then, even though the file/folder name is in the edit mode (highlighted or cursor inserted), when I try to type nothing happens (the name doesn't change). When this occurs, the keyboard functions properly in all other ways.
    Again, I can't isolate the circumstances leading up to this. Any ideas?

  • Protecting file/folder names/labels

    Anyone know of a way to protect, lock or "freeze" file/folder names/labels without locking the associated file or folder?
    Thanks,
    JD

    You cannot do that without changing certain permissions on the files. You can remove write permissions on the files, but then you wouldn't be able to make any changes to them, if you needed to, without restoring write permissions.
    Perhaps if you tell us why you've asked about this we could offer some additional ideas, if any.
    +BTW, you've posted in the Snow Leopard forum but your profile shows a G5 running Leopard. We appreciate it if you would post questions in the correct forums. This would be the wrong forum for your question based on your profile.+
    Message was edited by: Kappy

  • Apple script to replace content in specific folders with folder names in csv

    Can anyone please help me with this scenario... It would greatly be appreciated!
    1. I have a list in csv containing 3 columns: Column 1 = Folder name • Column 2 = Entry A • Column 3 = Entry B
    2. I have 100 folders named the same as Column 1.  in each folder there is different files.
    This is what I need.
    I need the script to to find the folder based upon column 1.
    Then the script should search for place holder named "Entry A" and replace it's contents with data from Column 2.  There are several files with in the folder that contain place holder "Entry A" so it should replace it all but must remain with in that folder.
    Then same for column 3 find place holder named Entry B and replace.
    Then it should save all files.
    Any help is greatly appreciated!  Thank you!

    Can anyone please help me with this scenario... It would greatly be appreciated!
    1. I have a list in csv containing 3 columns: Column 1 = Folder name • Column 2 = Entry A • Column 3 = Entry B
    2. I have 100 folders named the same as Column 1.  in each folder there is different files.
    This is what I need.
    I need the script to to find the folder based upon column 1.
    Then the script should search for place holder named "Entry A" and replace it's contents with data from Column 2.  There are several files with in the folder that contain place holder "Entry A" so it should replace it all but must remain with in that folder.
    Then same for column 3 find place holder named Entry B and replace.
    Then it should save all files.
    Any help is greatly appreciated!  Thank you!

  • Publishing bug with FTP servers - Spaces at end of file/folder names

    I'm sharing what I've found after lots of troubleshooting with my Mom's iWeb website. I originally came across this in the previous version of iWeb, and have seen it again in the current version.
    For the sake of this example, she had an image gallery on her site. The image file she added to iWeb had a space at the of the filename, just before the file extension, something like "image name .jpg"
    In the old version of iWeb (iWeb 08), we would publish the site to a folder on her computer, and it would generate a folder for each image in the gallery. These folders would hold the original image and thumbnail image. Each folder name was the image's filename, minus the extension. In this example, the folder name was "image name " with a space at the end, which is valid on the Mac OS X file system.
    When we uploaded it to the FTP site (which happened to be GoDaddy) using a 3rd party FTP tool, certain images would always fail to upload. After much testing and troubleshooting with other FTP software, we found that the FTP server did not allow spaces at the end of folder names, and it automatically replaced them with underscores. So, we tried to upload a folder called "image name ", and ended up with one called "image name_". As a result, we couldn't upload any of the files that were supposed to be IN that folder, because it could not be found under it's intended name.
    Fast forward to today, using iWeb 09. Now the software allows you to upload to a 3rd party FTP server, so we've stopped using the other FTP software and do it all in iWeb.
    She added a new image to her gallery and tried to publish changes, and got the error: "There was an error communicating with the FTP server. Try again lager, or check with your service provider"
    Once she removed the image, publishing worked again. It turned out the original image had a space at the end of the filename, just before the extension again. Once this space was removed, everything worked again.
    Hopefully this helps somebody else down the road. If you have trouble with certain files, check them for spaces at the end, just before the extension. Perhaps in a future release, Apple could update the site publishing code to trim leading/trailing spaces from folder names.
    If you've seen this before, or have any further questions/feedback for me, feel free to post a response. Thank you for reading.

    It would be nice if Apple could make their error messages more descriptive of the actual problem so we have a better idea of how to solve it. I am "the mom" who had the problem B2Ben posted about.
    The error message seemed to place blame on the ftp server or my ISP, consequently I wasted a lot of time with these people when it wasn't even remotely their fault.
    As with most computer problems, I ended up learning a lot from it and it always helps with gaining confidence. This is my 20th year as a Mac user!.. yes, since 1989. I look forward to seeing what some of you have experienced with this same issue.
    iMac GHZ PowerPC G$ Mac OS X (10.5.7)

  • Possible: renaming files - folder names as variables.

    Here's a bit of background - I have a rather extensive MP3 collection (all legal - I work for an independent music magazine in my spare time) - it's approx 7,000 files big now.
    I have them all stored in folders as follows:
    c:\SAMag\MP3's\Albums (and here comes the tricky bit...)
    EITHER
    \Artist Name Here - Album Title\<.MP3 files here> (No artist names contain a '-' so this is the seperator)
    OR
    \Artists Name Here\Albums Title One\<.MP3 files here>
    \Artists Name Here\Albums Title Two\<.MP3 files here>
    \Artists Name Here\Albums Title Three\<.MP3 files here> (Where there are more than one albums to an artist)
    Playing these files is a nightmare as they all have different naming conventions and odd ID tags. I want to remove all ID tags and rename them to have meaningful file names (so that WinAmp displays a decent, non-confusing, name).
    I would like:
    "<artist name> - <song title> (<album title> - <#>)"
    So, basically - is it possible to rename files in Java. Specifically: using the folder names that they are contained in as variables to put in this name?
    Thanks for any help people!

    Thanks for that.
    I'm pretty new to this whole Java thing (even though
    I've been attempting to do it for a while!) so was
    wondering if you could point me in the right
    direction.
    That is exactly what I did though.
    Do you have the javadocs? If so then you look up java.io.File and read the methods in it.
    Here is the online link....
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html

  • Strange character at the end of some file/folder names

    I'm getting a strange character at the end of some of my file and folder names. This is it:  When I enlarge it, it says "private use" on the top and bottom, "E000" on the left side, and "F8FF" on the right side. It acts like a character within the font, but I'm not sure why it's there.
    In case that didn't work, I'm going to try to attach or embed a gif of the character. I'm not sure if it will work or not.
    Also, some longer file names seem to be dleeting some of the letters and are inserting a pound sign and a few numbers (e.g. #34) in place of the letters.
    What's going on?
    As usual, thanks in advance,
    Lloyd

    I thought that might be it...at first. Then I found some file names that were nowhere near 32 characters long whose names were truncated.
    It's not a huge problem, except in QuarkXPress when I collect the files for output and I have to reconnect to the ones whose names have been changed (to protect the innocent, I suppose).
    Thanks for the input mark.
    Lloyd

  • Time Machine v.1 lost file folder names all the way back to "the beginning of time"

    I was experiencing some increasingly erratic system problems with my White 2006 iMac running OS 10.5.8. My guess is that these problems were due to power outages cutting power to the iMac while it was in use.
    - I tried Disk Utility from the Install Disk and it cleaned the HD but when I ran Verify Disk from Disk Utility off the HD it reported errors and I continued having problems.
    --  I decided to wipe the HD and reinstall everything.
    --- The first thing I did was backup with Time Machine v.1 and then disconnect the backup drive.
    ---  After reloading the OS and upgrades I ran Verify Disk from Disk Utility off the HD and it reported no errors.
    ----   Skipping all the headache a reinstall entailed ... I reloaded my files from the external backup drive Time Machine backups by grabbing the folders and pulling them to the cleaned HD.
    -----     I found large portions of files names missing. They look to be exclusively file names starting with a number that I use to order files ( 01. , 02. , 03. ... etc) as opposed to alphabetical listing.
    -----     These files - so far - are all located on a single folder branch. Meaning: as I follow the folder tree down I get to a list of project folders and some or all are missing everything but the starting number. I wrote this off as something to do with the hard drive operation problem but ...
    ------      ... all the same backup folders in Time Machine on my Seagate GoFlex have also lost their names all the way back for 2 years, when I started using Time Machine and the GoFlex.
    ------      I know for a for a fact the folder names were intact before I cleaned the iMac HD since I regularly use those files.

    They aren't what they appear to be on the TM, most are aliases to aliases to aliases when files are changed, I think only TM understands how/where the files are actually stored.
    Later versions of the OS with Restore Partitions can Restore also
    Do run DU on the TM drive... it certainly can't hurt at this point.
    I recommend cloning your drives instead of TM, not only can you copy files/folders over if needed, you can actually boot from your backup & continue working, or even clone back to the Internal...
    Get carbon copy cloner to make an exact copy of your old HD to the New one...
    http://www.bombich.com/software/ccc.html
    Or SuperDuper...
    http://www.shirt-pocket.com/SuperDuper/
    Or the most expensive one & my favorite, Tri-Backup...
    http://www.tri-edre.com/english/tribackup.html

  • Automator problem - Send text from file to email

    Hi all, I used automator on OsX 10.6 to send automatically the text within an HTML file to an email and then to a list of addresses. I installed 10.7 and now the thing doesn't work anymore.
    I did a couple of tests and it looks like the text taken from the file doesn't pass to the email body. Do you have any clue on how to do this?
    Thanks

    Hi,
    Print the whole stack trace. It will tell you the line which causes the error. How you use clob and blob in oracle is also version dependent. Try to google for
    oracle "your version" java clob example.
    /Kaj

  • Bridge Collection file / folder name single quote bug fix?

    Just starting using Bridge CS5 on WIndows 7.  Fresh install of OS and CS5.  Latest patches applied (4.0.5.11).
    After laboriously selecting 60+ files and creating a colelction, the collection showed zero items.
    I recreated the collection multiple times but same result.  This was supremely frustrating and a huge time waster for me (and I'm sure for others).
    Completely repeatable.
    Tracked this down to one of my folders having a single quote in its name.  This problem was documented back in 2010:
    http://forums.adobe.com/message/2936294
    I edited the collection file in notepad and replaced the single quote with %27.  Worked fine.
    But manually editting the collection file everytime I make a change to the collection or renaming my folder hierachry are not viable workarounds.
    Does anybody know if a fix was ever released for this?  What is Adobe's response to this? 
    It apparently is a regression (i.e. it was fixed in a pevious verision and now is back).
    This is a programming 101 bug (i.e. escaping special characters in file names). 
    This type of programing error is a real showstopper and really inexcuable, especially for how long it has been out there.
    Jeff

    Thanks for posting this problem on the photoshop feedback page.
    It's clear many of us have tripped on this issue and that it is time Adobe fixed this problem.
    To hedge our collective bets, I also filed a "bug report" using this web page:
    https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
    It interesting to note that I did not find a bug report form for Bridge - the site just offers a redirect to the general feedback form on Photoshop.  But there was a bug report form for Premier Pro (a program they obviously care more about).  So I filed this issue as an official bug against Premier Pro thinking it may get greater visiability.  What follows is what I submitted.  If I hear back from the development team I'll let this thread know.
    Jeff
    ******BUG******
    File names / folders with single quotes (e.g., Jeff's Photos) are not properly escaped in the collection xml file created by Bridge which is used to manage assets in Photoshop, Premier Pro, etc. The single quote, which is a valid filename symbol in Windows, should be converted to %27 in the xml file but is left "as is" which prematurely terminates filename / folder strings.  The net effect varies based on the operation being performed, but it is typically a silent error (i.e. the user is given no warning anything is wrong) and can result in catastrophic loss of critical assets.
    It is simple to repro: just create a folder with a single quote in the name, populate it with content files, and create a collection.  The next time you use it, the collection shows up as 0 entries.
    The bug (which appears to be a regression) results in many users losing critical asset files and wasting huge amounts of time debugging this issue which was reported almost a year ago.  The forums have many threads on this problem - see my recent entry for an example:
    http://forums.adobe.com/message/4112499#4112499
    The bug is a trap that directly erodes customer confidence and satisfaction with Adobe's whole product line.  Bridge is billed as hub that is supposed to tie all products together - but it cannot be trusted.  Critical assets and time are lost.  This is trivial bug to fix and many customers are outraged that Adobe has done nothing to fix it or warn users about it - especially since this is in your professional line of products that cost over a thousand dollars.  Please escalate this fix immediately. 
    As a courtesy, please let me know this bug report was escalated and an ETA when a fix may become available.
    Thank you

  • Drag-and-drop tree list from files/folder

    Hello all. I'm new to Flex and I'm looking for some help or
    for someone to point me in the right direction. I want to write a
    simple AIR application to accept a multiple text files (or a folder
    full of text files) when the files/folder is dragged into a tree
    list. The file/folder name will be the node name. When selected,
    the contents of the file will be displayed in a text area. The text
    file will contain a 4 x 4 number matrix with each column separated
    by a tab and each row separated by a return. (I plan on plotting
    the numbers in the matrix in the future).
    What I'm most confused about is how to go about
    dragging-and-dropping files into a tree list and creating item
    names based on the file/folder name? And does the file content need
    to go into an array collection?
    Maybe I'm going about this in a difficult way. If there is an
    easier way, I'd appreciate it if someone could share. Thank you
    all.

    I have the same problema and I´m not able to find the reason.
    The solution to get the event raised has been to copy configurations from wd standard appl FPM_TEST_DND_FORM and use my own Z feeder class : all  seems to work perfectly , but , if I try to do it from scratch the event  FPM_DROP_COMPLETED it´s not raised .
    I´ve compared both configurations/class ( the one that I´ve done from scratch  that it doesn´t raise the event and the one that I´ve adapted copying from standard that it raises perfectly  the event) and I haven´t  seen any difference (maybe I haven´t found) .

  • Finder not refreshing file or folder names, in NFS mounts.

    We are experiencing the an issues with NFS mounts, in both 10.7 and 10.8 machines.  After mounting NFS shares, the file/folder names do not update in other MAC finder windows until it is unmounted and remounted on the MACs.  This DOES NOT happen in our 10.6.8 and earlier machines.

    Cross posted
    http://forum.java.sun.com/thread.jspa?threadID=768693&tstart=0

  • I need a script that copies the filename into the file

    I need a script that copies the filename into 4th column of each line in the text doc file.
    I have over 2000 different file names each containing 6 columns and ~50-100 rows.
    I can do this manually using this script:
    awk '{print $1"\t"$2"t\"$3"\t <name> \t"$6}'
    But I would like an automation command or script. Is there any command that I can use instead of <name> that will copy the filename into the column?
    Thanks
    Monica

    Oops, I forgot the redirect to a file. It's not a good idea to edit files in place. A script could fail and you're left with at least one file ruined. It's better to create new files then delete the old files.
    for file in *; do
        while read col1 col2 col3 col4 col5 col6; do              
            printf "%s\t%s\t%s\t%s\t%s\n" $col1 $col2 $col3 $file $col6
        done < $file > n$file
    done
    You could narrow the files listed such as
    for file in *.tsv
    and redirect the new files to another directory. Such as
    done < $file > /absolute/path/to/directory/$file

Maybe you are looking for