将更改应用于不同位置的原始文件的可组织文件目录

问题描述 投票:0回答:1

是否有解决方法

来自不同外部硬盘驱动器的所有文件和文件夹的一个统一列表/目录,可用于移动和重命名项目,但是稍后在连接该外部驱动器时,相关文件/文件夹将根据以下信息进行重命名,复制,移动和删除在该目录中进行的更改。

这是因为连接所有外部HDD非常困难且麻烦,即使所有外部HDD都必须在组织所有驱动器中的每个文件的整个过程中都运行。

基本上类似于Adobe Lightroom目录,但用于文件和文件夹。我们可以处理目录,并且在连接HDD时将更改应用于原始文档。

applescript alias symlink diskspace file-organization
1个回答
0
投票

不用担心stackoverflow,经过三天的严格搜索,我找到了解决方案以完成所需的工作。

通过此过程,任何人都只能在一个小的访问包(几乎不包含MB)中拥有所有硬盘,服务器,NAS,云等中所有TB级文件的链接,并且可以对其进行组织,标记,重命名。并清洗。

然后,一旦完成,就可以用原始文件在其各自组织和修改的位置替换所有链接,而不会造成任何麻烦和硬盘驱动器运行时或紧张的情况。

[我使用苹果脚本告诉finder进行以下操作,但是由于缺乏编程基础以及文件系统的工作原理,到达解决方案时经历了几处曲折,转折,反复试验和错误。

SOLUTION:

苹果脚本的三个步骤

  1. 复制源文件夹和目标文件夹之间的目录结构,仅包含文件夹和子文件夹(全部)。但是使用文件的符号链接,而不是文件本身。

  2. 将所有符号链接转换为Mac finder类型的别名,以便可以使用Apple脚本对其进行处理。

  3. 将所有别名替换为其所指向的原始文件。

每个步骤的脚本也随屏幕截图一起发布,并带有详细的注释

STEP 0

STEP 1:

set sourceFolder to choose folder with prompt "Choose Source Folder"
(* To prompt a window with to choose source folder *)
set destinationFolder to choose folder with prompt "Choose Destination Folder"
(* To prompt a window with the title choose destination folder *)
tell application "Finder"

    do shell script "/opt/X11/bin/lndir " & quoted form of POSIX path of sourceFolder & " " & quoted form of POSIX path of destinationFolder & ""
    (* Using shell to execute "lndir" command with its path (as there was a 'command not found' error initially)
        and since we need to use HFS style paths of source and destination directories in the lndir command,
        we are using the quoted form of HFS path i.e. POSIX style (because apple script's POSIX style paths of sourceFolder
        and destinationFolder references used in the beginning lines of script are not used in shell *)

end tell


(* Installing lndir command to terminal is step 1 and it is downloaded using go from github (https://github.com/launchdarkly/go-lndir) *)

(* lndir command whihc is a unix command replicates the directory strucutre of folders and sub-folders between source and destination folders
excluding the files but places the symbolic links of the files instead in the destination directories *)

(* unix lndir man page (http://www.xfree86.org/4.3.0/lndir.1.html) *)

STEP 1

STEP 2:

set sourceFolder to choose folder with prompt "Choose Source Folder"
(* get a prompt windows to choose source folder *)

tell application "Finder"
    set allSymLinks to entire contents of sourceFolder
    (* define a variable allSymlinks so that every file in that folder is scanned for its kind and arrayed *)
    repeat with aSymLink in allSymLinks
        (* repeat the following for every file found (as a variable 'aSymLink') in the array made ('allSymLinks')*)
        if kind of aSymLink is alias then
            (* if the file type is an alias (which is the same for both symbolic link and a mac finder alias) then *)
            set posixPath to POSIX path of aSymLink
            (* set variable to the POSIX path of that file (as it is required for apple script) *)
            move aSymLink to trash
            (* move that symbolic link file to trash *)
            set aliasPath to POSIX file of posixPath as alias
            (* set a variable 'aliasPath' while making a POSIX file (a mac finder alias file)
            with the POSIX path acquired from the symbolic link before we moved it to trash *)
        end if
    end repeat
end tell

(* this script is an intermediary step only because the apple script would't work when we simply write the 'if' condition with kind is alias then...
as though the kind of Symbolic Link is alias, for some reason apple script didn't use it as it would with an original mac finder alias,
so we are converitng it to mac finder type alias using the POSIX path*)

(* Probably the reason might be that apple script can only fetch the original file if the path is of POSIX style *)

STEP 2

STEP 3:

set sourceFolder to choose folder with prompt "Choose Source Folder"
(* get a prompt windows to choose source folder *)

tell application "Finder"
    set allAliases to entire contents of sourceFolder
    (* define a variable allAliases so that every file in that folder is scanned for its kind and arrayed *)
    repeat with anAlias in allAliases
        (* repeat the following for every file found (as a varaible 'anAlias') in the array made ('allAliases')*)
        if class of anAlias is alias file then
            (* if the file's class type is an alias then *)
            set originalFile to original item of anAlias
            (* defining originalFile to the original file the alias is pointing to *)
            set containerFolder to container of anAlias
            (* defining contianerFolder to the folder the alias is pointing to *)
            move anAlias to trash
            (* deleting the alias to trash *)
            move originalFile to containerFolder
            (* moving the original file to the folder *)
        end if
    end repeat
end tell

(* Apple Script didn't work when like in the previous step's script If i wrote 'kind is alias', before I changed them to POSIX style alias,
which apple script seems to work with *)

(* Probably the reason might be that apple script can only fetch the original file if the path is of POSIX style *)

STEP 3_a

STEP 3_b

我希望所有这些都有一个应用

但是我永远都不会学到所有这些。

希望这对有需要的所有人有用。

Good Day] >>

© www.soinside.com 2019 - 2024. All rights reserved.