Script for finding characters in a folder or file name

I need some help on writing a script that will search thru users folders and files and replace characters in the names with a different character. Our users folders go back to when the users used OS 9 and they used / \ * ? in the file and folder names, I want to write a script that will replace these characters with an _ . Obviously I will need to be logged in as the root user.
The server is OS 10.3.9
Thanks,
Jeff
  Mac OS X (10.3.9)  

Hi Roger,
   There's a flaw in your regular expression and that is the absence of alternation. You want to replace any one of these characters with an underscore. That can be accomplished by putting the characters in a character class. Since the class matches a single character, you'll get an underscore for each.
   Your regular expression only matches a group of all of the characters, side-by-side, in the order you typed them and then it replaces the entire group with a single underscore.
   Oh, there's one other possible flaw. I think that the find utility creates lists of files in relatively large groups and then acts on them. If you change a directory that contains a file you want to change, it's possible that the change to the directory will not be reflected in the path to the file, causing a "file not found" error. A depth first search and acting only on the basename would eliminate that possibility.
Hi Jeff,
   I recommend a command like the following:
find -d /Users -regex ".[\:*?]." -exec echo 'mv "{}" "$(dirname "{}")"/"$(basename "{}" | sed '\''s/[\\:*?]/_/g'\'' )"' \; | sh
That uses the same character class in the -regex option of the find command. That way, nothing will be invoked unless necessary. The method of creating the text of a complex command and using the -exec switch to echo that into a shell is an old trick from O'Reilly's UNIX Power Tools.
   I substituted a colon for a forward slash. As the path separator, the forward slash isn't a valid filename character on a UNIX system. However, old Apple tools, including the Finder, still use a colon as the path separator. Therefore the system presents the allowable character as a forward slash to Apple tools and a colon to UNIX tools. Thus using the colon in the command above will have the effect you want on files that the Finder says has a forward slash in the name.
Gary
~~~~
   James Joyce -- an essentially private man who wished his total
   indifference to public notice to be universally recognized.
         -- Tom Stoppard

Similar Messages

  • How to make a script for find text object?

    Hi everyone
    I want to make a script for find and select text object and then find next, find next, and so on, but without any open dialog
    Is that possible make a script for this?
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = "(\[\x{2022}\])|(\x{25CF})";
    app.findGrep();
    thanks
    Regard

    You already have that. A script does not 'find, select, find next' - it finds all texts as soon as you execute the 'app.findGrep' command.

  • Install iTunes 10.4.1 install error - The Folder Path "File Name" contains an invalid character

    Upgraded computer from XP Prof 32-Bit to Windows 7 Ultimate 64-Bit (Upgrade package, performed Custom Install).
    Attempt to install iTunes 10.4.1 for 64-Bit.  Receiving the following error/problem:
    The Folder Path "File Name on my external drive" contains an invalid character
    I click ok and then get this:
    The Installer encountered errors before iTunes could be configured.  Errors occurred during installation.  Your system could not be modified,  Please run the installer again, or click Finish to exit.
    Any fixes for this?

    Sorry, one of us is not managing to be clear enough.
    Does the message read The Folder Path "File Name on my external drive" contains an invalid character or perhaps The Folder Path "<some path name here>" contains an invalid character?
    If so, then the problem might be just what it says it is with the path name in question... Either way if you list the path given in the error message in a reply to this thread it might provide a clue for anyone tying to help with the problem.
    You could try downloading the installer to C:\iTunesSetup.exe in case that helps.
    tt2

  • How do you rearrange photos in a folder by file name?

    How do you rearrange photos in a folder by file name on an ipad?

    I don't believe it's possible under the standard "Photos" app (built-in) in iOS.
    However, there appear to be many downloadable apps that will allow you to do this. Search the App Store for something like "photo sort".
    You may also want to leave Apple your feedback in regards to this at:
    http://www.apple.com/feedback/

  • Some items in finder windows have gray dots after file names

    When I open a finder window for the current directory, some of the file name shave little gray dots after the file names, off to the right at the end of the name field.  What do they mean?  Mavericks 10.9.4 on a 2009 Mac Pro.

    It means that the gray tag has been assigned to them.
    (110820)

  • Script for export all text in single rtf file?

    Hi!
    I need to export all storys from indd document to a single rtf file. Is there avaible some free script for CS4 which can do that?

    if(app.documents.length != 0){
         if(app.documents.item(0).stories.length != 0){
              myGetFileName(app.documents.item(0).name);
    //========================= FUNCTIONS ===========================
    function myGetFileName(myDocumentName){
         var myFilePath = File.saveDialog("Save Exported File As:");
         if(myFilePath != null){
              myDisplayDialog(myDocumentName, myFilePath);
    function myDisplayDialog(myDocumentName, myFilePath){
         //Need to get export format, story separator.
         var myExportFormats = ["Text Only", "Tagged Text", "RTF"];
         var myDialog = app.dialogs.add({name:"ExportAllStories"});
         with(myDialog.dialogColumns.add()){
              with(dialogRows.add()){
                   with(dialogColumns.add()){
                        var myExportFormatDropdown = dropdowns.add({stringList:myExportFormats, selectedIndex:0});
              with(dialogRows.add()){
                   var myAddSeparatorCheckbox = checkboxControls.add({staticLabel:"Add separator line", checkedState:true});
         var myResult = myDialog.show();
         if(myResult == true){
              var myExportFormat = myExportFormats[myExportFormatDropdown.selectedIndex];
              var myAddSeparator = myAddSeparatorCheckbox.checkedState;
              myDialog.destroy();
              myExportAllText(myDocumentName, myFilePath, myExportFormat, myAddSeparator);
         else{
              myDialog.destroy();
    function myExportAllText(myDocumentName, myFilePath, myExportFormat, myAddSeparator){
         var myPage, myStory;
         var myExportedStories = [];
         var myTempFolder = Folder.temp;
         var myTempFile = File(myTempFolder + "/tempTextFile.txt");
         var myNewDocument = app.documents.add();
         var myDocument = app.documents.item(myDocumentName);
         var myTextFrame = myNewDocument.pages.item(0).textFrames.add({geometricBounds:myGetBounds(myNewDocument, myNewDocument.pages.item(0))});
         var myNewStory = myTextFrame.parentStory;
         for (var i = 0; i < myDocument.pages.length; i++) {
              myPage = myDocument.pages.item(i);
              for (var t = 0; t < myPage.textFrames.length; t++){
                   myStory = myPage.textFrames[t].parentStory;
                   if (!IsInArray(myStory.id, myExportedStories)) {
                        //Export the story as tagged text.
                        myStory.exportFile(ExportFormat.taggedText, myTempFile);
                        myExportedStories.push(myStory.id);
                        //Import (place) the file at the end of the temporary story.
                        myNewStory.insertionPoints.item(-1).place(myTempFile);
                        //If the imported text did not end with a return, enter a return
                        //to keep the stories from running together.
                        if(i != myDocument.stories.length -1){
                             if(myNewStory.characters.item(-1).contents != "\r"){
                                  myNewStory.insertionPoints.item(-1).contents = "\r";
                             if(myAddSeparator == true){
                                  myNewStory.insertionPoints.item(-1).contents = "----------------------------------------\r";
                   } // if not exported
              } // for text frames
         } // for pages
         switch(myExportFormat){
              case "Text Only":
                   myFormat = ExportFormat.textType;
                   myExtension = ".txt"
                   break;
              case "RTF":
                   myFormat = ExportFormat.RTF;
                   myExtension = ".rtf"
                   break;
              case "Tagged Text":
                   myFormat = ExportFormat.taggedText;
                   myExtension = ".txt"
                   break;
         myNewStory.exportFile(myFormat, File(myFilePath));
         myNewDocument.close(SaveOptions.no);
         myTempFile.remove();
    function myGetBounds(myDocument, myPage){
         var myPageWidth = myDocument.documentPreferences.pageWidth;
         var myPageHeight = myDocument.documentPreferences.pageHeight
         if(myPage.side == PageSideOptions.leftHand){
              var myX2 = myPage.marginPreferences.left;
              var myX1 = myPage.marginPreferences.right;
         else{
              var myX1 = myPage.marginPreferences.left;
              var myX2 = myPage.marginPreferences.right;
         var myY1 = myPage.marginPreferences.top;
         var myX2 = myPageWidth - myX2;
         var myY2 = myPageHeight - myPage.marginPreferences.bottom;
         return [myY1, myX1, myY2, myX2];
    function IsInArray(myString, myArray) {
         for (x in myArray) {
              if (myString == myArray[x]) {
                   return true;
         return false;
    This is a revised version of the script --  not totally tested.
    Kasyan

  • Search settings - default to current folder and "file name" ?

    99.9% of the time, when I enter something in the search bar of the Finder window, what I want to do is:
    1. search is the folder that I'm in
    2. search for the "file name", and
    3. then sort the results by "date modified".
    Currently, problem is:
    1. I can only change the search area (which defalts to "This Mac") after the search has begun.
    2. Likewise, the default is "content"
    3. There's not even an OPTION for "date modified". The "Last Opened" option is rarely useful.
    Please help!
    Thanks
    ip
    Message was edited by: ideapower

    Francine Schwieder wrote:
    The only one who can help us is Apple. Obviously you find this just as ridiculous as everyone else does who actually uses their computer to do things.
    While I usually think this kind of sweeping generalization is unjustified, here I do not. Spotlight has great potential, but "ridiculous" describes the implementation perfectly. I'm not terribly upset by the default to search "This Mac" -- it really isn't much of a hassle to have to click the folder button -- but the loss of the ability to choose any folder or group of folders is exactly the kind of "regressive functionality" that should have people flooding feedback with complaints.
    Just as ridiculous is the inability to show & sort on any of the metadata columns a normal Finder window offers. And if "Last Opened" is so useful in searches that it is the (unchangeable) default, why isn't it available in any other Finder view?
    Plus, does anybody really understand how the "File Name" option works? It rarely seems to make a difference -- I often enter a search phrase, look at the results, then switch to the File Name option & still see files that clearly do not have the search phrase or any part of it in their names.
    More: Try a search on Kind "Other" & enter the "Kind" info from a file's Get Info Box. Try "Application (Classic)" & note that it finds any you might have. But try "Application (Universal)" or "Application (PowerPC)" & you get ... nothing. Try just "Application (" & you get all apps. Try "Classic" & once again, any Classic apps show up, but try "Universal" or "PowerPC" & you get nothing. It's the same with many other file kinds -- sometimes the "Get Info" file kind string or some part of it works, sometimes not. Worse, the same is true for the "Kind" info taken directly from Finder windows. Try entering "Plain Text" in the Kind-Other search. I have hundreds of these but the search turns up exactly one, & it isn't even in my Documents folder.
    (Before anybody suggests it, yes I have rebuilt the Spotlight index repeatedly, using both the Privacy pane method & Terminal commands, & it makes no difference.)
    The point is not to rant but to demonstrate how poorly thought out & unreliable the app remains. I feel the problems are so obvious & widespread that we should not have to use the feedback page to tell Apple about them, but apparently we do. It really is as if it was designed by people that don't have a clue about what a search engine should do or how to integrate it into a user friendly environment.

  • Utility or script "each clip = new movie and let media file = name"

    I've found out that if I want to split a clip at the playhead and make it a new AS-IS original with a unique media file name designation; I have to go through:
    file>export> as full quality movie > check the "selected clips only " box > copy and paste the name and then designate destination folder> CLICK and then wait until done. (Thank you Karl)
    Unfortunately, completing this process with 180 clips per project x 15 to 20 projects per quarter... well it was more than I was prepared to do.
    Therefore... is there anyone out there who could (or has already) program(ed) some kind of script/utility/add-on that would create a new AS-IS clip from each clip that was "split at the playhead" and ALSO, make those final clips as well as every other existing clip in the project have its media file designation the same as its name.
    ie "each clip = new full quality movie and let its media file = name."
    This would save me around 10 hours per week.
    mac pro   Mac OS X (10.4.8)  

    Karsten is correct. iMovie itself does not support AppleScript.
    But for applications that don't support AppleScript, Apple offers a "System Events" AppleScripting alternative. It lets an AppleScript script use System Events to do things in OTHER applications. It can act on window objects, like click on a button. Theoretically, System Events can do just about any task in iMovie.
    Except, unfortunately, select a clip.
    That's right, there is no way to select a clip with a script. So a script can't control which object to act on. YOU have to select the clip manually. That's not an insurmountable problem, but it does mean you can't tell the script to export every clip in the Timeline.
    Probably the easiest way to do what you want is with QuicKeys, the third-party software that lets you define tasks, then assign a key to perform that task. Just about any task you can imagine. One kind of task is a macro to perform a series of actions. QuicKeys lets you record macros in any application. Its record function makes macro-writing pretty easy.
    (QuicKeys is one of those utilities I wouldn't be without. I use QuicKey keys hundreds of times a day for repetitive tasks.)
    Back to AppleScript. Theoretically, QuickTime Player Pro can do what you want. QuickTime Player is VERY scriptable.
    Here's the trick: Each time we save the iMovie project, iMovie updates the "Timeline Movie.mov" that's inside the Cache folder (inside the project package). When iMovie saves, it sets the selected frames of that movie to match the selected clip in the TimeLine. When you open the "Timeline Movie.mov" in QuickTime Player, the selected video/audio matches the clip selected in iMovie.
    So after you select a clip in iMovie, an AppleScript could save the iMovie project (to update the Timeline Movie), open the Timeline Movie in QuickTime, Copy the selected frames, Paste them into a new movie, then save the new movie.
    Back to QuicKeys. QuicKeys can work across multiple applications just like an AppleScript. So theoretically you could run part of a macro in iMovie and another part in QuickTime Player. And, if I recall, QuicKeys can run AppleScript scripts.
    What you REALLY want is an application that knows how to read iMovie project files and automatically exports each clip to its own movie.
    Maybe I'm missing some simple work-around. That'd be sweeeeeet!
    Yup. Sometimes the best solution is to avoid the problem, not solve it.
    We can export a project to the camera, then re-import it to a new iMovie project. When we do, most clips on the Timeline return as discrete clips. Clips like titles will not be editable, of course.
    That is best done early on, before we add titles, transitions and such. Import the newly-shot video, do a rough edit to get rid of the stuff you don't want, export the Timeline to the camera, re-import to a new project. All the junk will be gone and now each clip is a discrete clip with its own source file. NOW add titles and such.
    Karl

  • Automator Folder Action: File Name = Spotlight Comment?

    Hey guys,
    I'm trying to have automator add the original filename of a file as spotlight comment when it is added to a certain folder. I can only use the "Set Spotlight Comments for Finder Items" in folder actions to add a specified comment, but nothing else. Is it possible to grab the file name via applescript?
    The idea behind this is to preserve the original file names of all downloaded files before they get renamed.
    Thanks,
    V

    Thanks for your reply, I now have your action installed and it does get the filenames, but I still can't add them to the spotlight comment text box. Looks like I didn't think this through properly.

  • Can I script the changing of creation date, using the file name?

    Normally people are doing this in reverse, but let me paint the picture.
    I pulled 204 video files from an old HDD based JVC camera.  JVC records in .MOD format which iPhoto won't import.  I imported them into iMovie just fine, and iMovie even set the file name to clip-2007-11-04 04;42;29.mov which is great, but it now has a new creation date of whatever date I imported it.  Which then causes problem when I want the videos stored in iPhoto and sorted appropriately by creation date.
    I've used the application "A Better Finder Attributes 5" to individually edit the creation and modify, but I'm sure I don't want to do this 203 more times, as you can't just type in the date and time, you have to type in each part of the date/time, or select it on a calendar.
    I've used the application "Name Changer" to batch convert the file names to the format YYYYMMDDhhmm which would be helpful if I were going to use the terminal command touch -t, but again I don't want to have to type it in 203 more times, plus drag and drop the file into finder to populate the location.
    Now, if I were more handy with automator, or maybe some (any) scripting language this would be easy peasy.  I'd batch rename all the files to the YYYYMMDDhhmm.mov and then have a script that just took the file name, passed that to touch -t along with the file location, and a few seconds later, they would all be done!
    Anybody have any suggestions to how I can do this, and tips to what commands to use or ANY advice?  I'm more than happy to RTFM, but I have no idea which manual to read!
    Thanks

    If your file names are precisely as you have written, this script will do what you want.
    Copy the script into an AppleScript Editor document, select one or more files in a Finder window, return to the AS Editor and press Run.  Note: you will need to provide your password when the script runs.
    Make sure you have a backup of any files you are working on (try using duplicates first, perhaps). The script has no error handling.
    tell application "Finder"
              set FileList to selection
              repeat with theFile in FileList
                        set fileName to name of theFile
                        set filePath to quoted form of (POSIX path of (theFile as alias))
                        set crYear to text 6 thru 9 of fileName
                        set crMonth to text 11 thru 12 of fileName
                        set crDay to text 14 thru 15 of fileName
                        set crHour to text 17 thru 18 of fileName
                        set crMins to text 20 thru 21 of fileName
                        set crDate to crYear & crMonth & crDay & crHour & crMins
                        set shellString to "touch -t " & crDate & " " & filePath
      do shell script shellString with administrator privileges
              end repeat
    end tell

  • Is there a way to sort files in a folder by file name in elements 11?

    When I want to print a contact sheet, I need the files pictures in the file name order. Elements 9 had this feature.

    I have different needs, but I agree the lack of alphanumeric sort should be fixed. In my situation, it would be enough to have an option to automatically sort an album in alphabetical order. I would also like a sort by caption for albums.
    In your case, that is with too many files in folders, the nearest workaround I have found would be:
    - Select the images you need to sort (a folder for instance) and export them without changing names in a new folder.
    - Import the result into the organizer.
    - Select all files in the import batch and assign them a common date stamp.
    Your copies should be shown in file name order, in thumbnail, folder or batch import view. But the date taken will be lost...
    A solution could be to select both the original images and the edited ones, use the 'automatically suggest stacks' based on visual similarity. You won't lose the date information, but at the cost of twice the disk space.

  • ICloud Drive shows 'Encrypted Folder' and 'Encrypted File' instead of correct folder and files names

    On my 2014 MBA (10.10.2), I added a group of folders and files to iCloud Drive in Finder by dragging and dropping.  I do not use disk encryption.  The files are of various types (mostly jpeg/pdf, and a few docx).  I can see the files when I login to iCloud.com, they are not showing as encrypted.  But on my iPad2 8.2 the folders and files show as Encrypted Files and Folders (Settings-iCloud-Storage-Manage Storage-Other Documents (under Documents and Data).  I have tried opening these with "authorized apps" on the iPad2, but the apps don't see these files.  Two questions: 1. Why are these showing as encrypted, i have no idea what is on the iPad2?; and 2. Once I can get an answer to 1., will I be able to open these jpeg and pdf files on the iPad2.  Thanks.

    Sorry we aren't communicating.  This doesn't have anything to do with a program being associated with the file.  No regular app can open an encrypted file.  Here is the final outcome.  For some reason, after 2 days, these files now show up as unencrypted files in iCloud Drive on the iPad.  That is they now match up by name and extension with what I have on the MBA in Finder.  There is no explanation except that iCloud Drive is buggy.

  • Need help for theRequirment:File2File Transfer by validating two file names

    Dear All,
    Kindly help me for the below requirement.
    Requirement:
    PI should pick two files from the FTP folder and will drop it to another FTP folder with out any mapping just pass through.these two files are having different Extensions(EX: .XML and .TXT) and its related to one another(two files data are related) so PI only transfer if both files are present else if there is only one file PI should not transfer the files.
    Note:File names are same for both the files with different extension(Ex: ABC_<timestamp>.XML and ABC_<timestamp>.TXT)
    thanks and Regards,
    Manikandan

    Hi Manikandan,
    One more option to do this without BPM:
    Try using the additional files option in the Sender File Channel.
    If source File name is MyFile.xml
    In additional files
    File List: MyFile.txt
    Parameters:
    MyFile.txt.namePart  -  ".xml"=".txt"
    MyFile.txt.optional  -  NO
    MyFile.txt.type  -  text/plain
    By having this setting done. The files will be picked only when both the files are placed and when both of them have the file names as "MyFile"
    Regards,
    Aravind

  • Elements 8 - How to view images by scrolling thru folder of file names?

    After taking a large batch of pictures, I want to place them in a folder and rapidly view the full images one at a time to select which to keep and which to discard.  IN PE-8 how can I display two panes - one pane containing the image file names contained in a folder and the other pane which displays the image of the file name selected?  Using the arrow keys, I want to move through image file names one at a time while displaying the image associated with the file name in the other pane.

      One method of accepting or rejecting is to use star ratings.
    Select the first image and press F12 to view full screen. Press the 5 key to add five stars.
    Press the right keyboard arrow to move to the next image and star or move on.
    When you have finished the batch you can filter by the star rating.

  • Labview IMAQ VI for capturing images and saving with incremental file names

    Hello,
    I am using LabView 7.1(IMAQ) to capture images with NI's PCI 1426 card, and a JAI CV-M2 camera. Now, with the example VI's like LL Grab, or LL Sequence, or Snap and Save to File.vi, I can capture the images. But what I actually want is to capture images continuously and keep saving them with a sequentially incrementing file name.
    I have tried to modify the Snap and Save to File.vi  by adding a 'for loop', so as to run this for required number of images. This works okay, but I can't really change the file name after every image. However, I'm not confident with this method either. I think it would be better to use the buffer itself, as is given in LL Grab.vi and somehow save images from the buffer. I think this would be faster ?
    In any case, any ideas as to how I should go about implementing auto-incrementing of the file name ?
    Any help will do. 
    Thanks.
    - Prashant

    Hi,
    Thanks a lot for replying. 
    I tried using this in the VI i was working with, but using the "build path" vi doesnt seem to work. If I use just the base path from user's input, it works, but then again it keeps overwriting the images into one file rather than giving each file a new name. I'm attaching the vi. 
    Please take a look and tell me where i'm going wrong.
    Thanks again.
    Attachments:
    LL Sequence_mod.vi ‏62 KB

Maybe you are looking for

  • L8 and L9 asking always for registration alternatively + Prob in Monitoring

    After few problem of hardware, i had to reinstalled an old backup system in which i had only L8. Reinstall L9 witouht problem . But everytime i activate L9 then L8 alternately they asked me to register before to open the application(things i did alwa

  • Oracle Exists Bug

    All, I have a doubt in the below sql Statement. select * FROM SISL_TXN_AGEING_TBL a where A.UNITHOLDERID = 'SBBNAC740162' AND A.DATEALLOTED_REV BETWEEN :FD AND :ED AND substr(A.txntype,1,2) ='03' and a.UNITSCONFIRMED <> 0 and exists (select 'x' from

  • FullScreenTakeOver, fullscreen, and fscommand exec

    I am not a programmer. I switched to CS3 for flv ease of skins, but I'm finding AS3 to be extremely difficult to learn. I have an .fla that I am publishing as a Mac projector and a Windows projector. It took me 2 days just to learn the new way to han

  • Random reset of ringtone volume since update to 2.0

    Since updating to 2.0 my ringtone volume level, which I keep on the hightest level, will randomly reset to mid-level, causing me to miss a number of calls. Anyone else notice this and is there a solution? Thanks

  • Acrobat Connect Trial - Crashes

    I'm excited to give acrobat connect a good go at-it but I haven't been able to resolve a big problem: I successfully get logged in to my room, "Acrobat Connect" comes up as a new application in my system tray and everything appears to be great. Until