【问题标题】:How to move folders to a new location with apple script如何使用苹果脚本将文件夹移动到新位置
【发布时间】:2018-02-09 16:22:23
【问题描述】:

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

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

文件夹

  • /Volumes/Netshare/Maxon/OLDFOLDER/library/scripts
  • /Volumes/Netshare/Maxon/OLDFOLDER/Off_Plugins

文件夹

  • /Users/name/Library/Preferences/MAXON/OLDFOLDER/library/browser
  • /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs

文件(没有结尾)

  • /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/xxx_net_80
  • /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/xxx_net_80_version4

文件(带结尾)

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

我将不胜感激任何可以指导如何实现这一点的帮助。我之前尝试了一些研究,但没有成功...

最好的

【问题讨论】:

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


    【解决方案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
    

    【讨论】:

    • 太好了,谢谢!我会努力适应它。当我有一个固定的文件列表时,我只需将 filesToMove 替换为一个列表,对吗?喜欢:将 filesToMove 设置为 {"file1", "file2", "file3"} 对于路径(桌面路径作为文本),我会将其替换为例如“Volumes:WhateverDirectory:WhereverFolder:”的路径与相对桌面路径不同,对吧?
    • 对于您使用固定文件列表的问题,答案是肯定的...只要您的文件列表不包含问题中示例中的 posix 路径格式... /Users/name /Library/Preferences/ for Finder 为了能够处理这些项目,需要使用 HFS 格式... "Macintosh HD:Users:Name:Library:Preferences"
    【解决方案2】:

    感谢@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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-01
      • 2015-11-15
      • 1970-01-01
      • 2019-04-18
      相关资源
      最近更新 更多