Move the file in the folder of the same name in AppleScript

I had a problem with the script below. Basically, on the execution of the script, I want to create folders based on the name of the file and move the files in the files of autocorrelation. However, at the minute, that I'll have to choose the folder in which the script should run.

Folder to choose a folder

say application 'Finder '.

located fileList to the name of every file in Folder with name extension is "m4v".

end say

the value point text delimiters to ".".

Repeat with dittos in list of files

get each text element of dittos

masterFile defined in the point 1 of the result

say application 'Finder '.

create a new folder to Folder with properties {name: masterFile}

move (each file from the folder Folder whose name contains masterFile) will cause

end say

end Repeat

Ideally, I would like it to run automatically, but the folder is on an external hard drive. (\Volumes\Lacie\Movies). and I had problems to use the POSIX and 'alias' to properly re-create the path of the file desired.

Any help would be greatly appreciated. Thank you!

Hello

You can try something like the AppleScript script which is a simple shell script wrapper.

set d to (choose folder)'s POSIX path
do shell script "/bin/bash -s <<'EOF' - " & d's quoted form & " 2>&1
cd \"$1\" || exit
shopt -s nullglob
for f in *.m4v
do
    m=${f%.*}
    [[ -d $m ]] || mkdir -p \"$m\" || continue
    mq=$(sed 's/[^[:alnum:]]/\\\\&/g' <<< \"$m\")   # quote meta characters for regex
    find -E . -depth 1 -type f -iregex '.*/'\"$mq\"'.[[:alnum:]]+$' -print0 | xargs -0 -J% mv % \"$m\"
done
EOF"

For example, given that you choose/path/to/directory in the folder - source

Input state:

/path/to/directory/abc.m4v
/path/to/directory/abc.txt
/path/to/directory/abcd.m4v
/path/to/directory/abcd.txt

Status of the output:

/path/to/directory/abc/abc.m4v
/path/to/directory/abc/abc.txt
/path/to/directory/abcd/abcd.m4v
/path/to/directory/abcd/abcd.txt

Briefly tested under OS X 10.6.8 but no guarantee of any kind. Please make sure that you have a full backup of the original files and directories before you run this kind of script.

Good luck

H

Tags: Mac OS & System Software

Similar Questions

  • Permissions do not update every time that a user moves a file from one folder to another in the Windows XP computer.

    Original title: folder permissions to move or copy.

    I have a problem that I'm sure has a simple explanation but I don't know.  I have a folder in the tree that whenever a user moves a file from one folder to another, the permissions do not update.  Yet if a user copies the folder to the same location, permissions to update as expected.  This only happens with XP.  If I try with Win 7, if the user moves or copies, update permissions.

    Has anyone seen this or have an explanation?

    Hello

    Your Windows XP question is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the IT Pro TechNet public. Please post your question in the forum TechNet for assistance:

    http://social.technet.Microsoft.com/forums/en/itproxpsp/threads

    Hope the helps of information.

  • I want to move virtual machines to a folder called Linux name, but we have several file of the same name in our Datacenter, please give me PowerCLI Script to move exactly

    I want to move virtual machines to a folder called Linux name, but we have several file of the same name in our Datacenter, please give me PowerCLI Script to move exactly.

    I tried to use for the function FolderByPath below, but don't know how to use it and have worked. Please help me in this.

    Function Get-FolderByPath {}

    < #.

    . Records of recovery SYNOPSIS by giving a path

    . DESCRIPTION the function will retrieve a record by its

    path. The path can contain any type of leave (folder or)

    Data Center).

    . Author NOTES: Luc relaxing

    . Path PARAMETER

    The path to the folder.

    This is a required parameter.

    . Path PARAMETER

    The path to the folder.

    This is a required parameter.

    . PARAMETER separator

    The character used to separate the leaves in the

    path. The default value is ' / '.

    . EXAMPLE OF

    PS > Get-FolderByPath-path ' Datacenter/Folder1/Folder2 ".

    . EXAMPLE OF

    PS > Get-FolderByPath-path "Folder1 > Folder2"-separator ' > '

    # >

    (param

    [CmdletBinding()]

    [parameter (Mandatory = $true)]

    [System.String []] ${Path}.

    [tank] ${delimiter} = ' / '.

    )

    {in process

    If (((Get-PowerCLIConfiguration).)) DefaultVIServerMode - eq "Multiple") {}

    $vcs = $defaultVIServers

    }

    else {}

    $vcs = $defaultVIServers [0]

    }

    {foreach ($vc to $vcs)

    {foreach ($strPath in $Path)

    $root = get-file-name of the server data $vc centers

    $strPath.Split ($Separator) | %{

    $root = get-inventory-name $_-location $root - server $vc - NoRecursion

    If ((Get-stocks-localisation $root-NoRecursion |)) Select--ExpandProperty name)-contains "vm") {}

    $root = get-inventory-name "vm" - location $root - server $vc - NoRecursion

    }

    }

    $root | where {$_-is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl]}|% {}}

    Get-file-name $_. Name - location $root. Parent - Server $vc

    }

    }

    }

    }

    }

    You can try to retrieve the object file by steps as well.

    Something like this for example

    $folder = get-data center-name 'LTX01-G8 | Get-file-name "LTX-servers | Get-file-name "LTX servers 0000 - 0299. Get-file-name Linux

    I guess the first qualification in your path was the data center.

  • Move icon missing in the files downloaded in the clouds, so how do I move a file in a folder?

    Move icon missing in the files downloaded in the clouds, so how do I move a file in a folder?

    If you are on the page of files where all your files and folders are listed, then there are two ways to move:

    The thumbnail (can only move a file or folder at a time):

    • Click the triangle to display under the thumbnail.
    • In the options that appear, select the Move button.

    The list view (can move several files and folders):

    • The check boxes for the files and folders that you want to move.
    • The menu bar at the top left changes has a Move button.

  • where to save the files under options the file name is duplicated how to remove an additional folder with the same name

    Under Options in Firefox, I clicked on save the files under downloads, but the file name twice and an additional file with the same name is created in the folder, i.e.:

    G:\Akbar's Songs\HAMARA DOWNLOADS\HAMARA FORUMS DOWNLOADS FORUMS

    As you can see the file repeats, how can I fix it?

    Also the music files, I download from a site of downloads as a WinRar file and I need to open it. Y at - it an option where the file opens automatically in the folder I chose?

    Thanks a lot for your help.

    Hi Akush, when you install 7 - zip, make itself the default application to open .zip and .rar files. So if you double click on the .rar file, it should open in 7 - zip. If you prefer to decompress immediately, right click the file and look for new 7 - zip items in the menu. I can't think of a way to do this automatically, however.

  • Cannot move the element 'name.extension"in the Trash because it cannot be deleted. I restarted the finder and still got the same message

    Cannot move the element 'name.extension"in the Trash because it cannot be deleted. I restarted the finder and still got the same message. little help?

    Why do you want to delete?

    Where is located? (This file)

    What is it?

  • 2 separated registered photos with the same name of file/number.

    How can I separate 2 or more photos with the same name of file/number. Consult us in the case that I see a photo and when I open it I see a different picture. The second photo is not the case in the folder, but still I need to save. It seems they are crushed.

    How can I separate 2 or more photos with the same name of file/number. Consult us in the case that I see a photo and when I open it I see a different picture. The second photo is not the case in the folder, but still I need to save. It seems they are crushed.

    =============================================
    FWIW... If a picture was crushed (replaced), it is unrecoverable.

    Are you saying that the vignette does not match the full size photo?

    How_exactly_are you look at one picture?

    John Inzer - MS - MVP - Digital Media Experience - Notice_This is not tech support_I'm volunteer - Solutions that work for me may not work for you - * proceed at your own risk *.

  • I want to copy all my jpg files to another directory (a portable hard drive) with some of the same names of JPGs, but not necessarily all. What will happen? The word 'COPY', will be some of the deleted files be added or nothing at all.

    I have a LOT of pictures in my computer (over a thousand) and I want to put them on a portable hard drive, I bought (1 terabyte) but I won't write any of the names of existing files with different images. IS THIS POSSIBLE? Do I need software or special hardware? I tried the copy/paste standard as well as move files to the new directory, but it seems that I can lose files. I'm not sure if the files that are missing (or lack, in my opinion) are not copied. When I finished emptying the directory, it shows that it is empty but the new directory does not seem to have any additional files that should be there based on the counting of the files before and after.

    Thanks for any help you can provide, Bill

    1: right-click and then drag the pix on the external drive. Release the right mouse button and choose copy here. They are there?  Now remove it from the computer.

    2: you can see pix of the same name overwrite each other, or be done with (1), (2), etc.. But even in this case, they will be interspersed with the former. If keep you them in separate folders with different names, that should not happen. Personally, I rename all the pix before storing them. You can select the set instead of the code of the camera and a group, rename the first holiday 2009 yo and the rest will be renamed holiday 2009 and each havf will one (1), (2), (3), after them.

    It is also a nice freeware tool which, among other things, can rename a group of photos easily.

    FastStone Image Viewer
    http://www.FastStone.org/

    Bruce Hagen
    MS - MVP October 1, 2004 ~ September 30, 2010
    Imperial Beach, CA

  • Renaming of files exe with the same name

    I have

    just installed a game on steam.  The package ended up being buggy, so it did not work.  But I found a solution on the Forum and he told me to rename these two files exe under the same name.  Its the only way to fix the game.  Others did and cela worked.  When I try to rename the file an error pops up telling me that I can't have two files with the same name.  In summary, this is what is happening.

    two files are: prince of persia.exe and princeofpersia_launcher.exe .

    Need to rename it to princeofpersia_launcher.exe to the prince of persia.exe

    An error pops up saying ERROR RENAME FILE or FOLDER: cannot rename princeofpersia_launcher: a file with the specified name already exists.  Specify a different file name.

    The problem is that these two exe files MUST have the name of prince of Persia: work.  Is it possible that I could do?

    It is not possible to have two files with the same name in the same folder.  Something is wrong with the instructions that you try to follow.  What do say exactly?  Can you give us a link for them?
    Boulder computer Maven
    Most Microsoft Valuable Professional

  • When you add pictures to the Vista image folder it creates a folder HIDDEN of the same name with two copies of the same image inside

    I use Vista 32 bit. I started to see this problem when I recently copy photos from an SD card.

    When you add pictures to the Vista image folder it creates a folder HIDDEN of the same name with two copies of the same image inside

    I saw hidden files enabled in folder options.

    Any help is appreciated.

    Hey guys... I found the answer... Problem is with the software vaio content analyzer that comes with the vaio...

    It just search for Vaio Content Analyzer (parameters) and deselect

    Video analysis
    image analysis
    analysis of the music

    I went looking for this crazy thing... used almost all types of online scan, and finally to find that it is caused by an internal software only...
    anyway thanks to all... Hope it helps someone in the future :)
  • Files and folders with the same name

    I am trying to unzip some files and folders and it works fine on my computer with Windows XP. However, when you use Windows Vista I can't because there are folders and files with the same name. After an internet search, it seems that the only suggestion is to extract the files in separate folders which then would allow them to keep the same name. The problem is I want what they in the same folder and they need to have the names they have.

    NOTE: I do have two files with the same name in the same folder, I have a folder and a file with the same name. I would have thought that this would be acceptable because they are two things separate, and given that it's great under XP.

    All solutions?

    You are right, if I make a file and a text file with the same name, it works fine. However, when I try to extract the files I need it tells me that there is already a file with the same name as the folder. He goes to tell me to choose a new name but my only options are 'try again', 'jump' or 'Cancel '.

    I think I can understand what the problem is. For some reason when you download the zip file, the computer seems to have added a few files side with any format other than "file." It is those who have the same name as the folders as if they were, and they could not be uncompressed because of this. I have no idea whence they came as they appear from nowhere (compared to my XP). I'm trying now unzip the files separately and exclude the strange s 'file '.

    Thanks for your help though!

  • DISABLE "there is already a file with the same name to this place.

    Window 7. 64 bit. How do you turn OFF DISABLE, CANCEL, DELETE, STOP the pop-up 'MOVE the FILE'?

    As a user since the days of DOS command lines and having had a routine all the way through to XP, this new window is one of the most annoying pop ups for an experienced user. If it isn't a swith toggle check box or an other power selection for this message, there must be. And if there is, you did it quite hard to find.

    The dialog box that appears in Windows 7 that starts with "there is already a file with the same name to this place. It lists then the three choices - "Copy and replace", "Do not copy" and "copy, but keep both files.

    I managed several libraries of forms which oblige me to replace the files throughout my day. I make a copy of the file I replace first of all, for archival purposes and this pop-up box is, well, it's boring. There must be a way to disable.

    This box comes up to move files and to copy the files.

    Any help in these turn off would be appreciated.

    See you soon.

  • Save the file with the same name

    How to change the script to save the file with the same name?


    
    
    
    
    //SaveforWebSP.jsx  
    
    
    
    //Save a fixed width image with a size constraint in its original folder  
    
    
     
     
    
    
    
    var docRef = activeDocument;  
    
    
    
    var outputFolder = docRef.path;  
    
    
     
     
    
    
    
    NamesaveRef = new File( outputFolder + "/reference.jpg" );  
    
    
    
    var NewfileRef = new File( NamesaveRef )  
    
    
     
     
    
    
    
    // quality/size constraints  
    
    
    
    var w = 1920; // new file width  
    
    
    
    var MaxSz =  361440; // max. 360Kb  
    
    
    
    var Qlt = 100; // initial quality 100  
    
    
    
    var x = 1; // decreasing step  
    
    
     
     
    
    
    
    // resize the image to the right width  
    
    
    
    docRef.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER);  
    
    
     
     
    
    
    
    // Perform the first SaveForWeb Operation  
    
    
    
    ExpWeb(NewfileRef, Qlt);  
    
    
     
     
    
    
    
    // Keep trying to save the file with max. Qlt, but under MaxSz 
     
    
    
    
    while (NewfileRef.length > MaxSz)  
    
    
    
    {  
    
    
          
    Qlt = Qlt - x;  
    
    
          
    NewfileRef = new File( NewfileRef );
     
    
    
          
    NewfileRef.remove();  
    
    
          
    ExpWeb(NewfileRef, Qlt);  // Perform a new SaveForWeb Operation, with slightly lower Qlt  
    
    
             
    if (Qlt <= 40) {  
    
    
               
    alert("The file can't be saved with the desired size AND quality.");  
    
    
               
    break  // break the loop whenever the quality is as low as 50 (this shouldn't need to happen)  
    
    
             
    }  
    
    
    
    }  
    
    
     
     
    
    
    
    var FileSz = NewfileRef.length/1024;  
    
    
    
    FileSz = Math.round(FileSz);  
    
    
     
     
    
    
    
    // close the original file without saving  
    
    
    
    activeDocument.close(SaveOptions.DONOTSAVECHANGES);  
    
    
     
     
    
    
    
    // SaveForWeb Export, with the desired constraints and parameters  
    
    
    
    function ExpWeb(FileNm, Qlt)  
    
    
    
    {  
    
    
          
    var options = new ExportOptionsSaveForWeb();  
    
    
          
    options.quality = Qlt;   // Start with highest quality (biggest file).  
    
    
          
    options.format = SaveDocumentType.JPEG;   // Save Format for the file  
    
    
          
    docRef.exportDocument(File(FileNm), ExportType.SAVEFORWEB, options);  
    
    
    
    } 
    
    
    
    
    

    Change of line 25 to:

     var docName = docRef.name.split('.')[0];
     NamesaveRef = new File( outputFolder + "/"+docName +".jpg");
    
  • Return of the mistake of MUSE: why do we not have several files with the same name?

    Well - I thought I had all this worked and fixed, but I met the download error 'Why do we have several files with the same name' once again.  (I downloaded all the files several times today in order to 1) works the way it worked the last time and 2) get an OAM file that is not loading for some reason any load again and the download takes about an hour to transfer all the files manually.

    To recap:

    (1) an option "Upload only modified files" returns the 'Muse has encountered an error and closes.  Why do we have several files with the same name? "error just as before.

    (2) a full download will work but takes forever and is NOT a substitution for work changed files option.

    Please advise with possible solutions!

    -Dave

    Is it possible to have two .oam different files in different folders on your computer where the .oam files have the same name? I'm theorizing that there may be a bug in the treatment to ensure the folder created for a .oam placed on the server receives a unique name, particularly in the case of a partial update of the site on the server.

    Please send us the .muse file and all the files in .oam related to [email protected] along with a link to this topic for the context so we can attempt to reproduce this error and isolate the root cause. If files are larger than 20 MB, you'll need to use a service such as Adobe send & Track, Dropbox, creative cloud, WeTransfer, etc. file sharing. Thank you.

  • Help! Need a script to automatically open files with the same name but in another location.

    Good morning friends,

    So for my work, I need a script to open files with the same name but located in a different folder. But since I'm a total noob when it comes to programming, I can't understand how do. That's what I have in mind:

    -J' I manually open an image.

    -The script will look for a file with the same name in another folder that I've specified.

    -The script will then select the channel CMYK of the second file and copy and paste it into the first file.

    -The second file is then closed without saving the changes.

    I have problems with the part where the script searches for a file with the same name as the opened file. I would really appreciate help. Thanks in advance.

    If (app.documents.length > 0) {}

    myDocument var = app.activeDocument;

    var Nomdoc = myDocument.name;

    try {var basename = docName.match (/(.*)-.)} [ ^\.] +$/)[1]}

    catch (e) {var basename = thedoc.name};

    var path = / * path of folder to insert as a string here * / + ' / ' + base name + / * insert file extension, including the period as a string here * /;

    If (queue (path) .exists == true) {var otherDocument = app.open (File (path))};

    };

Maybe you are looking for

  • Malware 2016

    Why do I not receive 2 notice of adware/malware in the second week of March 2016?

  • Problem starting after Sfc scan on my Pavilion 15-n012Tx

    Recently, I ran sfc scan, after that he told me to reboot my system. Then I tried to restart my system, but it has not turned on yet. I don't know how to solve this problem, help me please. My laptop model No 15-n012Tx with the windows operating syst

  • By the way the Pls/Sql variable to build xml via XQuery code

    v_ID number (3): = 5; v_UserID nvarchar2 (5): = 'abc '; v_Password nvarchar2 (8): = "passw0rd" v_Panel nvarchar2 (20): = "AppPnl"; v_loginFailReason nvarchar2 (200): = 'IUIP | Invalid user or password ID '; v_SpParam xmltype: = XMLTYPE ("< QueryParam

  • What should be the perfect setting to convert the VM model CLI?

    Hello team,I tried to convert the model of a virtual machine using the vim - cmd vmsvc/convert.toTemplate 1And I am facing this error:{(vmodl.fault.NotSupported)faultCause = (vmodl. NULL in MethodFault),MSG = "received error [< p:1f2aea80, TCP:localh

  • How can I reinstall without CD I've ever had?

    Hello!I try to reinstall my Adobe Creative Suite Design Standard CS5, 5.I have install fra this link: Download CS5.5 productsThrough the installation program ask me to insert the disc.But I'm sure that I don't have a disk when I bought, because I bou