Rename and Delete Files

Hi everyones, i'm new to this forum and to applescript
i need help to make a little script. i got a folder that look like this :
FOLDER_TOP
--FOLDER_1111a
-----AAAAA_1.jpg
-----BBBBB_2.jpg
-----PHOTO_3.jpg
--FOLDER_2222b
-----ABCDE_111.jpg
-----BBBB_233.jpg
-----PHOTO_456.jpg
The folder FOLDER_TOP can contain hundred of subfolder like FOLDER_1111a and FOLDER_2222b and each subfolder contain a lot of photos like AAAAA_1.jpg, BBBBB_2.jpg and PHOTO_3.jpg
I need to be able to rename the first photo of each subfolder by the name of the subfolder and delete the remaining ones (AAAAA_1.jpg must became FOLDER_1111a.jpg. BBBBB_2.jpg and PHOTO_3.jpg must be deleted)
Many thanks for yours help
Message was edited by: BOBaGINETTE

Hello
You're quite welcome. Glad to hear it works well so far.
As for variable extension, are you trying to do this? -
Provided a subfolder is named 'ddd' and its 1st file in lexical order is named 'mmm.eee' (mmm is a name stem and eee is a name extension), you are to rename the 1st file as 'ddd.eee' regardless of what the 'eee' is.
If so, try the following script.
I also revised the code a bit so that it can now properly handle the cases where less than 2 files is in a subfolder.
Hope this may help,
H
--SCRIPT b
main()
on main()
script o
property dd : {}
property ff : {}
property mss0 : "Choose top folder."
property mss1 : "You're processing items in tree rooted at:" & return & return
property mss2 : "Done."
set d0 to choose folder with prompt mss0
display dialog mss1 & d0 with icon 1
tell application "Finder"
try
set dd to d0's folders as alias list
on error from erob -- optional (not required) under OSX 10.5 or later
set dd to erob as alias as list
end try
end tell
repeat with d in my dd
set d to d's contents
tell application "Finder"
set ff to (d's files) as list
if ff is not {} then
set ff to (sort ff by name) as list -- optional if Finder always gets items in lexical order
set f1 to my ff's item 1
set e1 to f1's name extension
if e1 is not "" then set e1 to "." & e1
set f1's name to d's name & e1
set ff to my ff's rest
if ff is not {} then delete ff
end if
end tell
end repeat
display dialog mss2 with icon 1 giving up after 2
end script
tell o to run
end main
--END OF SCRIPT b

Similar Messages

  • Feature Request: Functions for Renaming and Deleting LrDevelopPresets

    As it stands, there is no way to delete an LrDevelopPreset programmatically - short of deleting the develop preset lrtemplate file, but even then the effect doesn't take place until after restarting Lightroom.
    Likewise, there is no good way to rename an LrDevelopPreset.
    Rename and delete functions would be very helpful to plugins that work with lrdevelopresets.
    Thanks,
    Rob

    Hi 
    Can you please post the archived project so that I can test in the latest internal builds and take the necessary actions?

  • Problem with Read-only user being able to add and delete files and folders.

    The setup:
    Computer #1
    iMac (intel) running 10.5.5
    File sharing ON
    Sharing folder on external USB drive called 'iTunes' (but not the drive volume itself)
    Users:
    - Everyone = Read Only
    - Admin(me) = Read/write
    - UserA = Read Only (with account PW and username identical to local login for computer below)
    Computer #2
    UserA's iBook G4 running 10.4.11
    When I go to finder>network>iMac>connect it prompts me to login which I do and then select 'iTunes' folder which is visible and mounts successfully. I can see all files, access them all. Life seems great. Then I discover that I can also modify and delete files from the iBook, and create and delete directories.
    I'm new to networking and although I've setup and managed minimal networking tasks on PCs before, this is my first foray into the Mac networking world. Please help.
    What am I doing wrong? What haven't I set?
    Thanks in advance.

    Sorry, I should have clarified this in the first email.
    When I login from the iBook, I am logging in under a read-only user (not as myself, who is admin on the iMac). The user on the iBook has only been given read-only permissions on the iMac yet is able to add and delete files.
    This read-only login/PW however, is the admin account on the iBook, but that shouldn't allow this person to write on the iMac so far as I understand things...right?

  • How do I store and delete files on the iphone

    how do I store and delete files on the iphone

    Files/documents need to be stored/associated within an app on the iPad, unlike 'normal' computers there is no file system which allows you to save files with no means of being able to read/use them. So if you want to store a file on the iPad you first need an app on the iPad that supports that file type.
    How you then get the file onto the iPad and into the app will depend on what the app is and what transfer method(s) it supports. e.g. some apps use the file sharing section at the bottom of the device's apps tab when connected to your computer's iTunes, some apps support the transfer of files via your wifi network, the iBooks app uses the Books section of your iTunes (and the device's Books tab) to sync content, and other transfer methods include email attachments, Dropbox etc. The file is then found by going into your chosen app and opening/using the file.

  • Selecting, Moving, and Deleting Files in Creative Cloud | Learn Creative Cloud | Adobe TV

    Get a basic overview of how you create new folders, move files into folders, and delete files within Creative Cloud.
    http://adobe.ly/LAfFwx

    HOW TO DELETE FILES or FOLDERS or Assets from Adobe Creative Cloud Brouser/Web Portal By: Kai Buskirk rev:130626
    http://forums.adobe.com/message/5449280#544928

  • My macbook pro keeps saying I have 450 gigabytes out of 500 that are used.  But when I look on finder there are no files that are anywhere close to that amount.  I went through and deleted files from my mac and now I only have 10 gs free

    My macbook pro keeps saying I have 450 gigabytes out of 500 that are used.  But when I look on finder there are no files that are anywhere close to that amount.  I went through and deleted files from my mac and now I only have 10 gigabytes of additional space free. My mac now says I have 440 gigs of other that is used. But does not make sense, do I have a virus?

    Since you have not identified the OS your MBP is using, these extract may or may not assist you.
    http://pondini.org/OSX/LionStorage.html
    http://pondini.org/OSX/DiskSpace.html
    You may also download from the Internet OmniDiskSweeper (free) and open it it will show all of the files on your MBP and the respective sizes.
    ciao.

  • [Thunar] Is it possible to remove trash and delete files instantly?

    Hi, I use xfce and I would like to know if it is possible to remove trash support and delete files instantly without having to hold shift key.

    @zoid Thanks i 'll give thunar no-trash a try.
    @david batson If i uninstall gvfs then I wouldn't be able to use removable devices, not to mention that files actually move to trash but there is no way of accessing it
    @lmsguer That's what I do so far.

  • Using foreach loop container with file system task to rename and move files

    the foreach loop container will not rename and move files for me
    sukai

    duplicate of
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/8f2899f1-43b0-47e0-8bd0-e082989cdcb8/file-system-task-and-foreach-loop-container?forum=sqlintegrationservices
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • IPhoto 08 and Deleting Files

    I recently upgraded from iLife 06 to ILife 08 and having major problems with new version of *IPhoto 08.* First and foremost, messages began showing that my startup disk is almost full and to delete unwanted files. I'm assuming this is happening because of ILife 08 installation including SuperDuper and Lacie external hard drive. No matter, before doing any installations I did massive backups to external hard drive and cds. Once ILife 08 was installed, I began deleting unwanted pictures within *_IPhoto Library via the Finder_* including File browser when I had Photoshop open. Unbeknownst to me, this is not recommended due to possible corruption of IPhoto. OK, apparent this is happening because when I go to IPhoto there are blank photos when I do a full screen.
    My question is what is the best way to delete ALL originals and duplicates of older iphoto 06 pictures including other unwanted pictures in current IPhoto 08 Library? Will I have to uninstall IPhoto 08 then go into my finder and start deleting pictures like I used to do whenever I wanted to delete files? Of course, even then I always had blank photos within IPhoto.
    BTW, with ILife 08 installed, I have deleted (trashed) all sorts of applications such as iMovie, and iDVD to free up space. This has made barely any difference. My main criteria is to delete HUGE pictures no longer needed in my IPhoto 06 (or rather IPhoto 08 too) Library Folders. Also considering I'm tapped with my current disk space, currently unable to download any programs such as duplicate annihilator, etc.
    Hope this isn't to confusing. Any help overwhelmingly appreciated!
    Cheers,
    June

    June
    Welcome to the Apple Discussions.
    Let's get this out of the way:
    Don't change anything in the iPhoto Library Folder via the Finder or any other application. iPhoto depends on the structure as well as the contents of this folder. Moving things, renaming things or otherwise making changes will prevent iPhoto from working and could even cause you to damage or lose your photos.
    The way to delete pics from iPhoto is to do it in the iPhoto Window. Drag the pics from the Library to the iPhoto trash. iPhoto Menu -> Empty the trash.
    Deleting a pic here or there is not going to make a difference to your HD space? How big are these pics? 2 - 5 mb if they're from a point and shoot camera, 10 - 15 from a dslr? Why not move your library to the external disk:
    1. Quit iPhoto
    2. Copy the iPhoto Library Folder as an entity from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    As you've been mucking about in the iPhoto Library Folder then you'll need to start over and create and populate a new library:
    To create and populate a new library:
    Note this will give you a working library with the same Events and pictures as before, however, you will lose your albums, keywords, modified versions, books, calendars etc.
    In the iPhoto Preferences -> Events Uncheck the box at 'Imported Items from the Finder'
    Move the iPhoto Library to the desktop
    Launch iPhoto. It will ask if you wish to create a new Library. Say Yes.
    Go into the iPhoto Library (Right Click -> Show Package Contents) on your desktop and find the Originals folder. From the Originals folder drag the individual Event Folders to the iPhoto Window and it will recreate them in the new library.
    When you're sure all is well you can delete the iPhoto Library on your desktop.
    In the future, in addition to your usual back up routine, you might like to make a copy of the library6.iPhoto file whenever you have made changes to the library as protection against database corruption.
    To use Photoshop with iPhoto:
    You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.
    Regards
    TD

  • How to open files with "return" key and delete files with "delete" key?

    Hi friends,
    It's been over a week since I got my iMac and I'm loving it. However, while I'm adapting alright to 'mac' key shortcuts (e.g. using the COMMAND-S for save as opposed to CONTROL-S used in PC).
    However, there are 2 things that are annoying me greatly right now.
    1. I like selecting files with keys as opposed to using the mouse. I make animations and prefer keyboard shortcuts. However, when I hit "return", instead of opening the file it goes into file-renaming mode. How do I change this? Likewise, I would like to delete files by hitting the delete key. This does not work - how do I change this?
    2. When I click SHIFT key sometimes, it gets 'stuck' - which is annoying because I start typing CAPITALS when I wasn't aware I've activated the CAP-LOCK key. How do I get rid of this? Like, I don't want to hit SHIFT for instance, and have that up arrow thing 'stuck' there.
    Your help would be greatly appreciated! Thanks!
    iMac G5   Mac OS X (10.4.9)  

    Hi
    Thanks for the star.
    If you went into Mac Help & searched, 2 results come up:
    Full keyboard access shortcuts for interacting with items (for selecting & activating controls).
    Full keyboard navigation keyboard shortcuts (for navigating Desktop, Windows, Menu bar etc)
    From the lists, select the link that closely describes your situation.
    I have to say that I can't reproduce your problem, does this happen just in applications or in everything? I don't know if it's to do with this but pressing Shift 5 times turns on Sticky Keys & Option(Alt) 5 times to turn on Mouse Keys (System Preferences>Universal Access>Keyboard).
    After typing "Sticky Keys" into Mac Help, I found this:
    "Pressing a group of modifier keys as a sequence
    To perform many tasks on your computer, you need to press one or more modifier keys (Shift, Command, Option, and Control) at the same time as another key. For example, pressing Shift-Command-Q in the Finder opens the Logout dialog.
    If you have difficulty pressing several keys at once, you can make it easier to press a set of keys by turning on Sticky Keys in the Universal Access preferences pane. With Sticky Keys turned on, you can press a set of modifier keys as a sequence. As you press each key, the symbol for the modifier key appears on the screen.
    Choose Apple menu > System Preferences and click Universal Access. Then click Keyboard.
    Select the On button next to Sticky Keys.
    To hear a sound whenever the computer registers that you have pressed a modifier key, select "Beep when a modifier key is set."
    To see an icon indicating which modifier keys you have pressed, select "Display pressed keys on screen."
    You can also use Slow Keys to adjust the amount of time between when you press a key and when it is activated."
    Any of this close to your problem?
    Steve
    Edit: I'm right, it's Sticky Keys:
    http://www.macusenet.com/190284-post2.html

  • FAQ: File Basics: How do I Upload, Download, Share, and Delete files in Revel?

    FILE BASICS
         Libraries:
    The top level of organization is Libraries
    Libraries can contain several albums.
    Libraries can have collaborative users that are invited to share. (requires Revel Premium) Invited users have access to add, delete and edit files. They must have a Revel account to do this.
         Albums:             
                     Albums contain photos
                     Albums cannot contain other albums
                     Albums can be shared with other users. They can be viewed, but not added or deleted by these users. People who view albums via shared links to not need to have a Revel account.
            *See SHARING topic below.
    CREATING LIBRARIES IN REVEL
    If you are a premium user, you can create additional libraries in Revel.
    CREATING ALBUMS  IN REVEL
    You can create new albums in your  revel library easily to help organize your photos. You can not have albums within albums. (nested albums)
    REVEL UPLOAD/IMPORT PHOTOS- copying files to Revel (cloud)
    From IPad, Iphone, Mac:  Upload to Revel is possible
    From a Browser: Upload to Revel is possible
    FROM Elements: Upload to Revel is possible
                How Do I upload files to Revel?
    REVEL DOWNLOAD/EXPORT PHOTOS FROM REVEL
    To Mac, IPhone, IPad:  export from Revel is possible (single or group export)
    To Android devices: export from Revel is possible (one file at at time)
    To computer using a web Browser: export from Revel is possible (one file at at time)
                 How Do I Download files from Revel?
    DELETING PHOTOS IN REVEL
    Deleting a file in Revel removes it from Revel (no devices will see it now) and removed it from the Elements Organizer. It should remain on the device in the original location.
    FAQ: How do I delete a file from Revel?
    DELETING FILES AND ALBUMS IN REVEL
                 FAQ: How do I delete a file or  an album from Revel?
    EDITING FILES IN REVEL
    You can open from and Save to Revel in the editors on mac/iphone/ipad. When you edit, your device will download the full image rather than having just the thumbnail.
    FAQ: How do I edit photos in Revel?
    SHARING FILES IN REVEL
    Collaborative sharing- can be done at the library level only. Other users are invited by email and must be logged into a Revel account to see the shared libraries.
    Read/download only sharing- can be done at the album level- a link is sent and the user does not need Revel to view them.
    Sharing of individual photos not currently available, creating your own personalized link name is not available
    FAQ: How do I share my photos in Revel?

    Hello All,
    As all you said I have used apache third party jars to upload a file into server.
    Thanks for help me out regarding this issue.
    But Now what the problem is When I run this locally it is running fine.
    When I deploy it on server It is giving the following exception.
    SRVE0026E: [Servlet Error]-[UploadLetter]: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUpload
    these files are in classpath.and successfully compiled but in runtime this is happening
    can anyone have any idea on this..??
    Please help me out.
    Thanks in advance.

  • I need to batch rename and relink files in indesign

    I have a whole bunch of files that I need to rename ( I need to add a prefix on to the front eg. a whole group of files called "plan.jpg" 01.jpg, 02.jpg, etc... need to now read ORD_plan.jpg, ORD_01.jpg, etc...) I can batch rename the files in adobe bridge, but I have to go in one by one and re-connect the links. Is there a script which can batch rename and relink all the files? 
    Thanks!

    This biterscripting script may possibly help. It takes two input arguments.
    directory - directory under which the .jpg files are located
    prefix - prefix which will be added to each file's name
    # Script RenameJpg.txt
    var str directory, prefix, list, filepath, name
    cd $directory
    find -n "*.jpg" > $list
    while ($list <> "")
    do
        lex "1" $list > $filepath ; stex -p "^/^l[" $filepath > $name
        set $name = $prefix+$name
        system copy ("\""+$filepath+"\"") ("\""+$name+"\"")
    done
    This is the way you would use it - copy and paste the script code into file C:/Scripts/RenameJpg.txt, then enter this command into biterscripting.
    script "C:/Scripts/RenameJpg.txt" directory("C:/test") prefix("ORD_")
    It will rename C:/test/plan.jpg to C:/test/ORD_plan.jpg, C:/test/01.jpg to C:/test/ORD_01.jpg, etc.
    Important: I am using the 'system copy' command so that files are copied instead of renamed. Once you are happy with the test, you can change that command to 'system rename'.
    Also, if the .jpg files are within subfolders of C:/test, change the 'find -n' to 'find -r -n'. -r means recursive = search in subfolders. Syntax for the find command at http://www.biterscripting.com/helppages/lf.html
    Message was edited by: Peter Spier to change 'path' to 'filepath' per post below
    Message was edited by: Peter Spier to change "perfix to "prefix"

  • Cant find and delete files

    Oh boy where do I start. I don't want to sound like one of these windows switchers who complains that things on a Mac seem complicated but things on my new Mac mini sure do seem so complicated.
    I've had my mini Server (2 x 1TB drives) only a little while, I'm running it alongside my Windows 7 PC which it is to replace eventually. I'm just familiarizing myself with it at present.
    The only thing I've done was to import 300Gb worth of photos/videos to the 'second' drive to have a play with iphoto, big mistake.  Iphoto constantly hangs and crashes, it cant seem to handle this amount of files so I deleted the pics/vids.  I've put nothing else on the Mac. 
    I then notice that the 'first' drive (the server drive) shows 320Gb worth of photos/videos on it?  They are the photos/vids I deleted from the second drive. How, I didn't put them there?  iphoto shows all pics/vids still there.
    I've spent hours trying to locate them, some seem to be on a dated folder: server-users-name-pictures-iphoto library-master (folder)- 2013-10-13-20131013-235601. Is this from me using Time Machine for a while? TM worked ok but the backups seemed to be getting very big so I switched it off and deleted all backups. 
    I only found the location above by taking a screenshot of a spotlight search, if I navigate in finder it only shows stuff up to 'iphoto library' nothing after. The 'iphoto library' is 75Gb but there are 300Gb in total. I've have finder set to show hidden folder.  In iphoto I put the files into trash and tried to delete them, it deleted some of them but it very easily crashes. There are some files iphoto won't let me put into trash saying it doesn't support those files and to use Aperture. (I don't have nor want Aperture).
    This is where I am now: some of the files seem to be in the dated folder above which I can't find (Finder doesn't seem very good at finding stuff). I can't delete the files from iphoto as it crashes very quick, in fact iphoto can now barely start up without crashing.  I don't know where the other 200+Gb files are but they are on the first drive. The object is simply to delete all the pics and vids on the first drive.
    No doubt one of you guys are going to show me some Mac magic to solve this problem in a flash making me look an idiot, well I'm cool with that just tell me what it is.
    Thanks in advance.

    iPhoto is, and always has been, a very cumbersome app.  That really doesn't have anything to do with Finder though. I used iPhoto way way back around version 4 or 5, before I took up "Photoshopping". I've had it on every Mac I've owned, but I don't think I've opened it since 2006. The iPhoto library takes up MASSIVE amounts of space and the bigger it gets, the harder it is to manage. Adobe Bridge does a much better job, and so does Photoshop.
    Once you get used to the ins and outs of Finder, you'll see that it's more intuitive than Explorer. Things it does that Windows may or may not ever do, like showing a complete file path from the top of window with just a right click on the title.
    And that's just a start.

  • Rename and move files on remote FTP server

    Hello,
    We have a scenario where XI transfers a file to a remote FTP server at partner end using File Receiver Communication channel.
    These files are huge,so there is a risk of picking up incomplete files at their end when XI is still writing the file on their server.
    Hence,we have decided to follow the approach which is already mentioned a number of times on SDN that XI would place a file with different name and in a different folder on partner's FTP server.
    This would then be renamed and moved to the required folder on the same server.
    This could easily be managed using a script at partner end but there are some problems when they are not able to do this.
    Is there a possibility to achieve this using 'Run OS command after Message Processing' in XI when Source and target folders both are on partner's FTP server?
    If yes,can anybody please provide code for such a script and corresponding setting for this parameter in XI Communication channel?
    Thanks a lot in advance.
    Best Regards,
    Shweta

    Hello,
    Thanks for the reply.
    But this has to be done in FTP session because the source and target directory both are on remote FTP server.
    Instead,in SAP documentation,I found a parameter :
    ftp.putSafe=YES|NO
    Use this specification to define whether a transferred file is first created with a temporary name and only renamed once the transfer is complete (YES), or whether it is created with its final name at the start of the transfer (NO). The latter case can lead to problems if an application on the FTP server accesses the file before the transfer is complete. If you specify YES, this problem is avoided because the file only becomes visible with the search name when the transfer is complete.
    The default value is NO.
    Doesn't it serve the same purpose?Do we still need to write scripts?
    I have tried to include this in Additional Parameters in Advanced Mode as:
    ftp.putSafe  YES
    but I can't check in test system whether it is really working or not.I would like to confirm if it helps.
    First of all,I would like to know if this setting works for XI3.0 SP17.
    Can anyone please help.
    Thanks.
    Regards,
    Shweta

  • MARS - NFS on Unix Services for Windows and deleting files

    Hello !
    I've prepared NFS server on W2k3 server with Unix Services for Windows installed. It works OK, the only problem is moveing/deleting files and folders. It seems like a problem with permissions for anonymous user. Does anybody have similar experience ?

    If you receive the following error message "Error ./pnarchiver Thread 2051:PN-0102:SQL error: ORA-01005: null password given; logon denied" then there is a Problem with archiving to NFS server. The directories for the archiving are properly created on the server but those directories remain empty. The workaround is that an inter operability issue exists between MARS and CygWin NFS server running on Windows 2003 server. To work around such inter operability issues, replace the NFS server with Microsoft Windows Services for Unix.

Maybe you are looking for

  • Which HP Printe ?

    I need to get a new printer and want to make sure I can print to it via my network/WIFI and my iphone/ipad. It seems confusing which HP printer is airprint enabled. Any one can give me a UK list Thanks

  • Error 4280

    I'm trying to burn from a playlis and all I get is error 4280 can anyone help? presario 3000   Windows XP   cd/dvd teac dw-22e

  • Available objects and fragmentes depending upon template selection

    Hi We have a use case where we have several different templates. For each template the user is to have access to only some objects and fragmentes. For example for the car template the user have access to car_registration, number_of_doors. While for i

  • Purchased Mountain Lion upgrade for Snow Leopard ... but ???

    I paid my $19.99 and went through the process, but after my computer restarts the Download mountain Lion icon is still there, space on my hard drive is used and when I go to "About This Mac" it still shows that I'm running 10.6.8 and the Snow Leopard

  • Problem viewing AS pane on screen..

    Hi All a really daft one this... i cant see all of the AS in the AS code pane (f9) the pane is to long and i cant see how you can resize it? i can change the width, but the bottom of the pane is below by monitor window.. i have tried changing my moni