2016-05-06 9 views
0

私は2つの部分に問題があります。上場絶対パスワット/ 255文字以上

パート1(ターミナル) - 私は、WindowsベースのシステムへのアーカイブはそれほどMac環境で働いています私はアーカイブの前にそれらのファイルを変更することができるように私は255のパスの長さを検出する必要があります。 StackOverflowでファイル名の長さに関する多くの解決策を見てきましたが、絶対パスの長さが必要です。私はこのスクリプト時に起こった、それは近いです:

sudo find . -name \* -type f | perl -ne 's/(.*)/print length($1), " $1\n" if (length($1)>254)/e' | sort -n 

問題は、私は絶対パスの長さを見ていないよということで、私は、現在のディレクトリからのパスの長さを見ています。リストされたすべてのファイルの絶対パスを表示しながら、現在のディレクトリ内でファイルを再帰的に検索する方法はありますか?

パート2(Applescript) - パート1がターミナルで正しく動作したら、プロセスを少し自動化したいと思っています。私は、フォルダがFinderで強調表示されているときに、コマンドを実行することができ、ターミナルがポップアップしてコマンドとリストを実行するというAppleScriptを作成したいと思うことが好ましい。これは私がこれまで持っているものです。

tell application "Finder" to set theSel to selection 
tell application "Terminal" 
set theFol to POSIX path of ((item 1 of theSel) as text)  
if (count of windows) is not 0 then 
    set shell to do script "cd " & quoted form of theFol in window 1   
do script "find . -name \\* -type f | perl -ne 's/(.*)/print length($1), \" $1\\n\" if (length($1)>254)/e''" in shell  
end if 
activate 
end tell 

問題は、私はこのAppleScriptを実行すると、コマンドは動きを通過し始めたが、その後立ち往生し、私が見るすべては

> 

私はあるということですctrl + cを押して、ターミナルウィンドウを使用し続ける必要があります。

誰も私がターミナルコマンドに表示されていないフラグを知っていますか?また、強調表示されたディレクトリの255文字以上のファイルの絶対パスと文字数を取得して一覧表示する別の方法もあります。

+0

端末を使用する必要がありますか?それの目的は何ですか?あなたが求めている真の結果は何ですか? – ThrowBackDewd

答えて

0

私は、このような状況でターミナルを使用することからどのような価値を得ているのかよくわからないので、ここには私がそれなしで追加した解決策があります。

on run 
    set longPaths to {} 
    tell application "Finder" to set theSel to selection 
    repeat with aFile in theSel 
     set aFile to aFile as string 
     set pathLength to count of characters in aFile 
     if pathLength > 255 then 
      set end of longPaths to aFile 
     end if 
    end repeat 

    if longPaths is not equal to {} then 
     -- do something with your list of long paths, write them to a text file or whatever you want 
     set pathToYourTextFile to (path to desktop folder as string)&"SampleTextFile.txt" 
     set tFile to open for access file (pathToYourTextFile as string) with write permission 
     repeat with filePath in longPaths 
      write (filePath & return as string) to tFile starting at eof 
     end repeat 
     close access tFile 
    end if 
end run 
+0

私はApplescriptの一般的な無知をお詫びします(上記は非常に役に立ちます)が、デスクトップにあるテキストファイルにリストを書き込む最も簡単な方法は何ですか? –

+0

@AlexNoble - 出力をテキストファイルに反映するために上記のコードを更新しました – ThrowBackDewd

+0

ありがとう、これは素晴らしいです! –

0

は、だけではなく、cd commandの使用のfindコマンドにフォルダのパスを置きます。あなたのAppleScriptでdo scriptコマンドの

tell application "Finder" 
    set theFol to item 1 of (get selection) 
    if class of theFol is not folder then return -- not a folder 
end tell 
set f to quoted form of POSIX path of (theFol as text) 

tell application "Terminal" 
    do script "find " & f & " -name \\* -type f | perl -ne 'print length($_), \" $_\", if length($_)>255'" -- (>255 characters), because the $_ variable contains a newline 
    activate 
end tell 

情報::あなたはperlコマンドの最後に2つの単純な引用符文字を入れているので、あなたのコマンドは、ターミナルで立ち往生このよう