如何使用Apple脚本将文件夹移动到新位置

时间:2018-02-09 16:22:24

标签: file applescript move directory macos-high-sierra

我不知道如何设置一个苹果脚本,将带有内容的文件夹移动到新的loacation,这些文件夹已经存在。如果是这样,Finder应该覆盖这些文件夹。但是在同一个过程中我也有特定的文件,应该将它们移动到一个新的位置。我不明白如何让它发挥作用。

这些是我要移动和覆盖的文件和文件夹: OLDFOLDER>来源,应该用目的地覆盖> NEWFOLDER

文件夹

  • /卷/ Netshare / Maxon公司/ OLDFOLDER /库/脚本
  • /卷/ Netshare / Maxon公司/ OLDFOLDER / Off_Plugins

文件夹

  • /用户/名称/库/首/ MAXON / OLDFOLDER /库/浏览器
  • /用户/名称/库/首/ MAXON / OLDFOLDER /首选项

文件(没有结尾)

  • /用户/名称/库/首/ MAXON / OLDFOLDER /首选项/ xxx_net_80
  • /用户/名称/库/首/ MAXON / OLDFOLDER /首选项/ xxx_net_80_version4

文件(带有结尾)

  • /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/c4d_M_GLOBAL_POPUP.res

我很感激任何帮助,如何实现这一点。我之前尝试过一些研究,但没有取得成功......

最佳

2 个答案:

答案 0 :(得分:1)

这适用于我使用最新版本的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

答案 1 :(得分:0)

Thanx to @ 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