代码之家  ›  专栏  ›  技术社区  ›  Hirschferkel

如何使用apple script将文件夹移动到新位置

  •  -1
  • Hirschferkel  · 技术社区  · 7 年前

    我不知道如何继续设置一个apple脚本,将文件夹及其内容移动到一个新的位置,这些文件夹可能已经存在。如果是,Finder应该覆盖这些文件夹。但在同一个过程中,我也有特定的文件,这些文件应该移动到新的位置。我不知道该怎么做。

    以下是我要移动和覆盖的文件和文件夹: 旧文件夹(>);应使用目标覆盖的源(&T);新建文件夹

    文件夹

    • /卷/Netshare/Maxon/OLDFOLDER/库/脚本
    • /卷/Netshare/Maxon/OLDFOLDER/Off\u插件

    文件夹

    • /用户/名称/库/首选项/MAXON/旧文件夹/库/浏览器
    • /用户/名称/库/首选项/MAXON/旧文件夹/首选项

    文档(无结尾)

    • /用户/名称/库/首选项/MAXON/旧文件夹/首选项/xxx\u net\u 80
    • /用户/名称/库/首选项/MAXON/OLDFOLDER/prefs/xxx\u net\u 80\u版本4

    文件(带结尾)

    • /用户/名称/库/首选项/MAXON/OLDFOLDER/prefs/c4d\U M\U GLOBAL\U弹出菜单。物件

    我将非常感谢任何能为实现这一点提供指导的帮助。我以前尝试过一些研究,但没有成功。。。

    最好的

    2 回复  |  直到 7 年前
        1
  •  1
  •   wch1zpink    7 年前

    这适用于我使用最新版本的Sierra

    -- Set The Variables To Your Folder Locations
    set folderToBeMoved to (path to desktop as text) & "Folder_To_Move"
    set destinationFolder to (path to desktop as text) & "New_Location"
    
    -- Select Files You Want To Move To A Different Location
    set filesToMove to choose file with prompt ¬
        "Choose Files To Be Moved" invisibles false ¬
        multiple selections allowed true ¬
        without showing package contents
    
    -- Move Files To Different Folder 
    tell application "Finder"
        repeat with i from 1 to number of items in filesToMove
            set this_item to item i of filesToMove
            set moveFiles to move file this_item ¬
                to destinationFolder ¬
                with replacing
        end repeat
    end tell
    
    -- Move Folder To Different Folder 
    tell application "Finder"
        set moveFolder to move folder folderToBeMoved ¬
            to destinationFolder ¬
            with replacing
    end tell
    
        2
  •  0
  •   Hirschferkel    7 年前

    Thanx至@wch1zpink

    我得到了必要的脚本,可以对我的案例进行一些改进。下面是它的工作原理:

    -- Set The Variables To Program Netshare Folder Locations
    set NetsharePath to "Macintosh HD:Volumes:Netshare:Maxon:"
    set NetshareFolderOrigin to NetsharePath & "19.044_RB221380"
    set NetshareFolderDestination to NetsharePath & "Testfolder"
    -- (path to desktop as text) & "New_Location"
    
    set NetshareFoldersToMove to {":library:scripts", ":Off_Plugins", ":plugins"}
    set NetshareSubfolderDestination to {":library", "", ""}
    
    -- Move Netshare Folders To New Folders 
    tell application "Finder"
        repeat with i from 1 to number of items in NetshareFoldersToMove
            set folderToBeMoved to NetshareFolderOrigin & item i of NetshareFoldersToMove
            set NetshareFolderDestinationCombination to NetshareFolderDestination & item i of NetshareSubfolderDestination
            set netMoveFolder to move folder folderToBeMoved ¬
                to NetshareDestinationFolderCombination ¬
                with replacing
            -- duplicate folderToBeMoved to NetshareFolderDestinationCombination
        end repeat
    end tell
    
    -- Set The Variables To Preferences Folder Locations
    set Username to "USER"
    set PreferencesPath to "Macintosh HD:Users:" & Username & ":Library:Preferences:Maxon:"
    set PreferencesFolderOriginName to "19.044_RB221380_FDCD4BE0"
    set PreferencesFolderDestinationName to "Test"
    set PreferencesPathOrigin to PreferencesPath & PreferencesFolderOriginName
    set PreferencesPathDestination to PreferencesPath & PreferencesFolderDestinationName
    
    set PreferencesFoldersToMove to {":_bugreports", ":bug.html", ":library:browser", ":library:layout", ":prefs:cache", ":prefs:directorycache",":prefs:c4d_M_GLOBAL_POPUP.res", ":prefs:CINEMA 4D.prf", ":prefs:shortcuttable.res", ":prefs:template.l4d", ":prefs:template.prf"}
    set PreferencesSubfolderDestination to {"", "", ":library", ":library", ":prefs", ":prefs", ":prefs", ":prefs", ":prefs", ":prefs", ":prefs"}
    
    -- Move Preferences Folders To new Folders 
    tell application "Finder"
        repeat with i from 1 to number of items in PreferencesFoldersToMove
            set prefFolderToBeMoved to PreferencesPathOrigin & item i of PreferencesFoldersToMove
            set PreferencesDestinationFolderCombination to PreferencesPathDestination & item i of PreferencesSubfolderDestination
            set prefMoveFolder to move folder prefFolderToBeMoved ¬
                to PreferencesDestinationFolderCombination ¬
                with replacing
            -- duplicate prefFolderToBeMoved to PreferencesDestinationFolderCombination
        end repeat
    end tell