Apple Script to rename single files in folders

Hey guys, I am trying to write a script to automatically rename a lot of files.  Here is the situtation:
I have a MainFolder with many SubFolders inside.  Inside each SubFolder is 1 word document.  Is there a way to write a script that automatically renames each of of those word documents to its folder's name.  Example.
BEFORE:
                  -SubFolder1 - 1.doc
                  -SubFolder2 - 1.doc
-MainFolder -SubFolder3 - 1.doc
                  -SubFolder3 - 1.doc
AFTER:
                  -SubFolder1 - SubFolder1.doc
                  -SubFolder2 - SubFolder2.doc
-MainFolder -SubFolder3 - SubFolder3.doc
                  -SubFolder3 - SubFolder4.doc
Thanks.

The following script should do what you are asking for:
set mainFolder to choose folder
tell application "Finder"
    repeat with thisFolder in (get folders of mainFolder)
        try
            set name of (file 1 of thisFolder whose name extension is "doc") to (name of thisFolder & ".doc")
        end try
    end repeat
end tell
If there's just one file in each subfolder (wich is not exactly the same as “one Word document”), you could remove the “whose name extension is "doc"” filter.

Similar Messages

  • Automator or Apple Script To Move Multiple Files to Multiple Folders

    I was just wondering, is there any sort of automator workflow or maybe apple script that will allow me to automate the following:
    I have a folder named SCANS containing multiple different files that need to go to multiple different folders.
    So Say I have:
    SCANS
    and in this folder I have ten files named A,B,C,D,E,F,G,H,I,J and I want each of these files to be moved to different folders eg.
    A I want to go to folder 1
    B I want to go to folder 2
    C I want to go to folder 3 etc etc.
    Anyone know if there is a way of doing this please?
    I have tried a workflow where I find finder items in the Scans folder and move to another but that only seems to work for one file.  When I add more it does not seem to work.
    Any help/guidance would be appreciated.
    Thank you!

    Hi Niel,
    Not quite what I wanted because I missed some information from my question....
    What I actually want is to search for files containing certain text in the name and if positive to then move that file to the specified folders.
    Cheers.

  • Apple Script to rename images using CSV file

    Hello, I have build a website using a Woocommerce for Wordpress. The site is going to have over 1200 images and they need to be renamed appropriately for each product. I've never used Apple Script before but after hours and hours of searching I have noticed people with similar issues have managed to solve the problem using AppleScript.
    I have attached a screenshot of the CSV file first 20 files - also the images are all saved in a folder with the names _DSC7916 copy 2.jpg etc etc.
    Hopefully my issue makes sense,

    In applescript it goes something like this:
              this all assuming the CSV file is a plain text file with a comma delimiting
              the old and new filenames on a given line. If you have another structure
              you need to give specifics so this can be modified
    set theCSVData to paragraphs of (read "/path/to/theCSVFile.csv")
    set {oldTID, my text item delimiters} to {my text item delimiters, ","}
    repeat with thisLine in theCSVData
              set {oldFileName, newFileName} to text items of thisLine
              tell application "System Events"
                        set name of file oldFileName of folder "path/to/folder of images" to newFileName
              end tell
    end repeat
    set my text item delimiters to oldTID
    Note that I've made a lot of assumptions about your csv file, any or all of which may be wrong. please clarify as needed.

  • Apple Script to rename files based on a style

    Hi I want to rename many files so they can uploaded to my website.
    In order for them to be uploaded they must be formatted in the following way.
    Firstname=Lastname=lab=summary
    I would input the firstname, lastname and summary for each file as that info is unique. Every file name's style will be the same. the first letter capiatlized in Firstname and Lastname and "lab" in non caps. there is also a "=" between all the words, no spaces.
    Is it possible to make an applescript program where I can drop the files in to the program and have a form open asking me to complete the FIrstname, Lastname and SUmmary fields while filling in the rest?
    Thanks in advance for any help.

    I'm confused about the details of the request.  can you describe the process more clearly? 

  • Script to rename multiple files

    I have about 30k image files on my pc in 1 dir C:\TEMP1\ for example. These files all have to be renamed to a specific unique name. Aside from these files I also have an xml file that contains properties for these files, document title, document id for example.
    The xml file also contains the path and file name of the image files. I need a script that can read the xml file, find the tag <ExternalRef> and then go out to C:\TEMP1\ and rename that file according to other xml tags such as document title and document
    id. I have 1 xml file for all 30k images. I dont have any scripting experience and was looking for some help.
    This is what the xml file looks like: So I need to find <ExternalRef>file://C:\TEMP1\000E57BC.TIF</ExternalRef> and rename that file to <DocumentTitle>Probate Order-SO</DocumentTitle> _<ABC_DocumentID>APO24L977</ABC_DocumentID>...etc
    - <ABC_TitleDocument>
    - <ABC_TitleDocumentProperties>
      <ObjectType>1</ObjectType>
      <Creator>Administrator</Creator>
      <DateCreated>2013-10-07T16:45:27.237Z</DateCreated>
      <LastModifier>Administrator</LastModifier>
      <DateLastModified>2013-10-07T16:45:27.237Z</DateLastModified>
      <Id>6132c424-007b-4ef9-9c07-2b8171b83357</Id>
      <Name>Probate Order-SO</Name>
      <SecurityPolicy />
      <SecurityParent />
      <IsFrozenVersion>0</IsFrozenVersion>
    - <VersionSeries>
    - <ObjectRef>
      <ObjectId>1be7c26c-89d2-40bf-afeb-a081714e470a7</ObjectId>
      <ClassId>01a3a8c8-7aec-11d1-a31b-a0020af9fbb1c</ClassId>
      </ObjectRef>
      </VersionSeries>
      <MajorVersionNumber>1</MajorVersionNumber>
      <MinorVersionNumber>0</MinorVersionNumber>
      <VersionStatus>1</VersionStatus>
    - <ContentElements>
    - <ContentTransfer>
      <ObjectType>1038</ObjectType>
      <ContentType>image/tiff</ContentType>
      <RetrievalName>000E57ABC.TIF</RetrievalName>
      <ExternalRef>file://C:\TEMP1\000E57BC.TIF</ExternalRef>
      </ContentTransfer>
      </ContentElements>
      <MimeType>image/tiff</MimeType>
      <DocumentLifecyclePolicy />
      <DocumentTitle>Probate Order-SO</DocumentTitle>
      <SourceDocument />
      <OwnerDocument />
      <PublicationInfo />
      <IgnoreRedirect />
      <EntryTemplateObjectStoreName />
      <EntryTemplateLaunchedWorkflowNumber />
      <EntryTemplateId />
      <ABC_Area>P</ABC_Area>
      <ABC_DocumentCategory>Title</ABC_DocumentCategory>
      <ABC_DocumentClass>11</ABC_DocumentClass>
      <ABC_DocumentID>APO24L977</ABC_DocumentID>
      <ABC_LandArea>151</ABC_LandArea>
      <ABC_ScanDate>2013-10-07T05:00:00Z</ABC_ScanDate>
      <ABC_ScanOperator>Administrator</ABC_ScanOperator>
      <ABC_ScanWorkstationID>SCN04:Sess 3</ABC_ScanWorkstationID>
      <ABC_Agency>03</ABC_Agency>
      <ABC_DocumentType>ABC</ABC_DocumentType>
      <ABC_LTRO>P</ABC_LTRO>
      <ABC_KofaxID>{DA701CAD-5CB2-444e-9ABBB-47CF0B2FD801}</ABC_KofaxID>
      <ABC_DocumentCount>11</ABC_DocumentCount>
      <ABC_Recordable>1</ABC_Recordable>
      <ABC_BatchType>FOLLOW-UP</ABC_BatchType>
      <ABC_EStamped>0</ABC_EStamped>
      <ABC_RecordationState>PENDING</ABC_RecordationState>
      <ABC_FileName />
      <ABC_FolderName />
      <ABC_BatchName>10/7/2013 8:25:26 AM</ABC_BatchName>
      <ABC_RecordDate>11/19/2004</ABC_RecordDate>
      <ABC_DocumentDate>1977-03-30T05:00:00Z</ABC_DocumentDate>
      <ABC_ConveyanceType>SO</ABC_ConveyanceType>
      </ABC_TitleDocumentProperties>
      </ABC_TitleDocument>

    I'm still quite new to this, but I think this would do the trick based on what you've supplied, note the -whatif so it doesn't screw up if the output isn't quite what you want.
    [xml]$fileinfo = Get-Content -Path .\fileinfo.xml
    foreach ($doc in $fileinfo.ABC_TitleDocument) {
    $filepath = $doc.ABC_TitleDocumentProperties.ContentElements.ContentTransfer.ExternalRef -creplace "file://",""
    $fileext = (Get-Item -Path $filepath).Extension
    $newfilepath = "$($doc.ABC_TitleDocumentProperties.DocumentTitle)_$($doc.ABC_TitleDocumentProperties.ABC_DocumentID)$fileext"
    Rename-Item -Path $filepath -NewName $newfilepath -WhatIf

  • Using a script to rename a file from the file info cart Cut Num (ID)??

    Hi,
    Can any of you guys tell me if its poss to do a script to rename a wav with the file info, cart, Cut Num ID field....??? (Cart chunks)
    Example file at the moment is called {C5E5F0FE-57D9-4A9A-8DA1-58D1AE7017FD}.wav and I want to grab the info out of the File info, cart section, under Cut Num (ID) which has 9558 in it and rename the file so it is now 9558.wav when it saves or just renames it.I also then want to run the script as i have 6000 plus wav,s to do this too.
    Thanks for any info.
    Glen

    >Can any of you guys tell me if its poss to do a script to rename a wav with the file info, cart, Cut Num ID field....??? (Cart chunks)
    No, scripts in Audition won't let you do this at all. In fact, Audition's scripting function really isn't very file-friendly, relating pretty much just to basic Audition functionality. And there's no way that an Audition script would let you rename a file anyway - they the closest they get to handling any file-related functions is that you can open a designated noise reduction profile - but that's about it.
    There's one place that I know of where you might find a utility to do what you want -
    here (try WidgetPro).

  • Easy way to rename all files and folders in a specific directory

    hy all,
    i want to rename all files&folders in a specified folder... i only want to replace all "_'_" with an"-" in all file names...
    example:
    TCHK1_B4194W01PF7_NMOSi_D_B__3_50ohm-500ohm_03-29-07_10'46'23_AM.tst
    TCHK1_B4194W01PF7_NMOSi_D_B__3_50ohm-500ohm_03-29-07_10-46-23_AM.tst
    i cant change the timeformat because this are automatically generated files from an external program...
    this is my program(attached as JPG) but it doesnt work...i get allways "error 10-duplicate path" or "error1 -   An input parameter is invalid"
    could sombody please help me... i think its an easy VI but i cant get it working
    THANKS in advance!!!!
    greets
    Andreas
    Attachments:
    renamefolder.JPG ‏20 KB

    Well, the one problem you have is that for the "Move" function, the source file input should be wired to the output of the "Build Path" function, not to the duplicate path out of the "List" function. Also, you need to pass the error cluster around with a shift register. Otherwise you will not catch an error that may have occurred during one of the file rename operations.

  • Editing/renaming mp3 files and folders on my Zen Micro with Win Media Player

    Can anyone tell me how I edit and rename the files all ready on my Zen Micro? For instance: I have 3 folders named "2Pac", "2 Pac" and "Tupac" and would like to put them all together under one name.
    I also want to get rid of the album subfolders. I have changed the files in the Library, renaming files and folders, deleting all album names, but the changes don't seem to be made on the player.
    I can't seem to change them directly changing folders and renaming files on the right side of the Media Player Screen either. Only option there is to delete files.
    Bepppe

    Thanks for the tip Baldbear, that should work.
    So I guess it is no way of editing the files when they are all ready on the player.
    Is it then impossible to get rid of the album subfolders? (without deleting all files an transfer them back on again. I would have done it if it weren't for the fact that the sync stops for no reason every 5th to 30th file I transfer.

  • Script for renaming postscript files

    I need a script that will rename a postscript file at the time of printing. Ideally, after you hit the print button, a field would appear for you to enter the new name of the postscript file prior to sending it on to the printer. After you entered text, you hit enter again and the file goes to the printer for printing. The print log would show the new name. If anyone knows how to do this, I would appreciate your assistance. I could probably get you some cash.
    Thanks,
    Rich

    This forum is for scripting questions rather than script requests.
    Please start by reading the following:
    Posting guidelines
    Handy tips for posting to this forum
    How to ask questions in a technical forum
    Rubber duck problem solving
    How to write a bad forum post
    Help Vampires: A Spotter's Guide
    -- Bill Stewart [Bill_Stewart]

  • 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!

  • Trying to write a simple apple script to reveal a file.

    This is what I have now:
    tell application "Finder" to reveal POSIX path of "/Users/lloyd/Desktop/my file.txt"
    but I get this error:
    error "Finder got an error: Can’t make \"/Users/lloyd/Desktop/my file.txt\" into type item." number -1700 from "/Users/lloyd/Desktop/my file.txt" to item
    Any help is much appreciated

    Thanks for the quick answer.  Tried changing to file but am now getting this error:
    error "Can’t get POSIX file of \"/Users/lloyd/Desktop/my file.txt\"." number -1728 from POSIX file of "/Users/lloyd/Desktop/my file.txt"
    btw, I meant to type reveal instead of open but don't think that should be a problem right?  The file exists on the desktop, does the space in the file name create a problem?

  • Install and uninstall of dmg file using Apple script in Mac 10.6 and higher version.

    Hi ,
    Could anyone please help me to write a Apple script to Install dmg file and do clean uninstall in Mac 10.6.8 and higher version.
    My requirement is:
    When i run script : it has to install the dmg file which is located inside one desktop folder say 'New Folder'
    I need to do clean unistall when i run the script: i need to delete the folder in ~/Library- locate folder say  'CPSPCSHOWSERVER'' move to trash and from Terminal type in command "rm -r ~/.CPS' to completely delte this folder.
    Really appreciated all ur help!!
    Thanks,
    KT.

    http://macfidelity.de/2008/08/30/how-to-mount-a-dmg-from-terminal-in-mac-os-x/in dex.html
    http://osxdaily.com/2011/12/17/mount-a-dmg-from-the-command-line-in-mac-os-x/
    http://hints.macworld.com/article.php?story=20030614230204397
    http://www.commandlinefu.com/commands/view/2031/install-an-mpkg-from-the-command -line-on-osx

  • Problems adding reg subkey in Single File Installer script

    Hello,
    I am having some problems with a script in my Single File Installer package im creating with the Installation Server Admin
    Background:
    I want to eliminate the users from having to pick the Kerberos token when we roll out SSO. To do this I need the following key in place for each user.
    HKEY_CURRENT_USER\Software\SAP\SecureLogin\TokenType = Kerberos
    I already confirmed that I can get this key injected by the Windows system when a user (new user or existing user) on the machine by putting in the following keys under HKLM. This is really cool trick if you didn't know already, I have not seen it used here at SCN before, but I ot it from previous experience.
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\slctoken\
    String: Version"
    Value: "1"
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\slctoken
    String: StubPath
    Value: "reg add "HKEY_CURRENT_USER\Software\SAP\SecureLogin" /v "TokenType" /d "kerberos" /t REG_SZ /F"
    Problem: 
    I can create registry values with this line I also use:
    NwEngine.Shell.SetRegValue "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\SAPLOGON_INI_FILE", "REG_EXPAND_SZ", "%userprofile%\AppData\Roaming\SAP\Common\saplogon.ini"
    But when I try to create new values in HKEY_CURRENT_USER\Software\SAP\SecureLogin it doesn't work. I think it is because the SecureLogin key does not yet exist. (this can be names anything, I made it up)
    Question: (in short)
    How can I make a registry subkey with a script inside the Single File Installer? I could also put a bat or vbs in the CustomerFiles folder and  run it, but I don't know how.
    My users have admin rights, and ultimately this will be pushed with LANDesk as System. So rights is not an issue.

    Yea I confirmed NwEngine.SetRegValue is NOT writing the subkey, it just doesn't run if the subkey isn't in place. Windows command "reg add" will write the subkey for a value if its no there.
    Also, im not writing to HKCU, im writing to a special place in HKLM. The key im writing will make the keys in HKCU during logon of the user. So I can run this as system, or local admin.
    I allready have a LANDesk SAP installer, useing a VBScript that runs the sap installer, along with out OpenText installer
    Here is my VB that is used with LANDesk or SCCM.
    ' Install SAP
    Function Install_SAP()
      If OSArch = "x64" Then
      If objFSO.FileExists(strProgramFiles64 + "\SAP\FrontEnd\SAPgui\saplogon.exe") Then
      Else
      strCurrentDir = Left(WScript.ScriptFullName, (InstrRev(WScript.ScriptFullName, "\") -1))
      application = chr(34) + strCurrentDir + "\sapgui\sapgui730.exe" + chr(34) + " /NoDlg /Package=" + chr(34) + "Esri" + chr(34)
      objShell.Run(application),1,true
      End If
      Else
      If objFSO.FileExists(strProgramFiles + "\SAP\FrontEnd\SAPgui\saplogon.exe") Then
      Else
      strCurrentDir = Left(WScript.ScriptFullName, (InstrRev(WScript.ScriptFullName, "\") -1))
      application = chr(34) + strCurrentDir + "\sapgui\sapgui730.exe" + chr(34) + " /NoDlg /Package=" + chr(34) + "Esri" + chr(34)
      objShell.Run(application),1,true
      End If
      End If
    End Function

  • Sending email using apple script...

    I have created a watch folder using apple script that when a file is dropped on it, it automatically opens, formats, and sends out a custom email.
    What I don't understand is, how can I include multiple variables in the "content" section (also known as the body section of the email)? I want to put custom type in the content section that says "There is a file awaiting your review." I also would like to choose an email signature from my mail program to use. Third, I would like to include the name of the file that is being sent....
    I found that by doing {content:iteminfo} I could get the file name...If I do {content:"There is a file awaiting your review."} I could get the custom type I wanted....
    BUT, I can't figure out how to get BOTH of them together in ADDITION to adding a custom email signature...
    I know there are some really smart people out there...Any tips?

    I can't figure out how to get BOTH of them together
    This is just standard AppleScript text concatenation with the &:
    ... {content: "There is a file awaiting your review: " & iteminfo}
    Here you can see I'm concatenating a literal string (enclosed in quotes) and a variable. You can extend this ad infinitum.
    As for the signature:
    tell theMessage to set message signature to signature "My Sig"
    (which assumes you have a signature named 'My Sig'. Adjust as necessary.

  • Using c++ variable in apple script

    Hi all,
    I am just calling the apple script from my indesign plugin.
    I need to pass the c++ variable to apple script for opening a file
    This in my apple Script which i have embedded in c++ code
    tell application "TextEdit"
    activate
    open "Users:User1:Library:Preferences:Adobe Indesign:Version 5.0:MathEQ.txt"
    end tell
    The filepath "Users:User1:Library:Preferences:Adobe Indesign:Version 5.0:MathEQ.txt" is stored in the C++ variable char* textFileName.
    I need to use the variable textFileName in apple script which has the path.
    How to go about it?
    Thanks
    Sakthi

    I have a similar problem trying to get data from any field into an AppleScript variable.
    Something like *set phoneNumber to cell "Phone Number" of current record* works fine if you are using the script from a layout that has this field on it.
    But I have a lot of fields on different layouts and I want to have access to all fields in the table, no matter what layout they are on, or what layout is currently active.
    And I want to do this without having to specify on what layout each field is located.
    In the past (FileMaker 6) I used something like *set phoneNumber to (cell "Phone Number" of current record of database 1)* but this is no longer working in FileMaker 9.
    So I was thinking to use something like *set phoneNumber to cell "Phone Number" of current record of table "Table Name"* but that doesn't seem to work.
    The only thing that seems to work is *set phoneNumber to cell "Phone Number" of current record of layout "Layout Name"* but as I said, I don't want to specify the layout for each field.
    Any ideas anyone?
    Message was edited by: khasmir

Maybe you are looking for

  • IPhone 3G will not sync to iTunes whatever I do

    iPhone 3G iTunes 10.5. Macbook Pro 15" i5 processor iOS 4.2.1 (which I believe is as far as it will go) Having real trouble syncing the entire contents of my iPhone. I can go through the whole process either via right-clicking on my iPhone in the dev

  • Using Airplay with TV off

    Hi all, I have read what has been said o nthis topic on the boards.  I have my Apple TV with an optical out and HDMI out both going to a receiver.  I can switch receiver HDMI outputs (watch a show on tv) with the Apple TV sound still working.  Howeve

  • When I sync my Ipad to my computer, i am getting a different capacity.

    When I sync my Ipad to my computer, i am getting a different capacity.

  • Column level security

    Hi, While changing PROJECT_INACCESSIBLE_COLUMN_AS_NULL to YES in NQSConfig file to implement the column level security, we get an error saying 'A general error has occurred. [nQSError: 46036] Internal Assertion: Condition m_CountFields == static_cast

  • Cold Fusion MX and Windows 7

    Hi, has anyone had experience with installing CF MX on a Windows 7 system? I had trouble with Vista. I am planning to buy a new computer and they are all on Windows 7. I want to make sure if I will be able to have my CF MX installed on it without hav