The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   Networking (http://hintsforums.macworld.com/forumdisplay.php?f=14)
-   -   Count Path Characters before upload to server (http://hintsforums.macworld.com/showthread.php?t=101195)

cwtnospam 05-02-2009 09:26 AM

Launchd would probably work, but Windows would screw up the path for any files whose path was greater than 255, so the script would fail.

tw 05-02-2009 11:07 AM

well, solving one problem, I've discovered it's actually very easy to identify files whose paths will be too long. the following applescript (which takes a normal file system alias for theItem) should do it:

Code:

set theItemPath to POSIX path of theItem
set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
set chop to -2
if last text item of theItemPath is "" then set chop to -3
set theParentPath to text items 1 thru chop of theItemPath
set AppleScript's text item delimiters to tid
set theServerBasePathLength to 17
set theCurrentBasePathLength to length of theParentPath
set cmd to "find " & quoted form of theItemPath & " | awk 'length($0) - " & theCurrentBasePathLength & "+" & theServerBasePathLength & " >255' -"
set theFileList to do shell script cmd

now it's just a question of when and how the OP wants to call it, and what to do with the files that are too long.

jeremyoliver 05-14-2009 11:34 AM

I'm not sure what to think of this discussion. Again, I wouldn't know what to do with any of that coding. I don't want the server to have to do anything.

I want to do a quick character check on certain files before I throw them in my backup folder on the server. So far, it seems like my primitive method of using the triple column view and estimating character count based on 1" is approx 13-15 characters is the quickest and least complicated. agreed?

thanks everyone.

tw 05-14-2009 12:03 PM

Quote:

Originally Posted by jeremyoliver (Post 533036)
I'm not sure what to think of this discussion. Again, I wouldn't know what to do with any of that coding. I don't want the server to have to do anything.

I want to do a quick character check on certain files before I throw them in my backup folder on the server. So far, it seems like my primitive method of using the triple column view and estimating character count based on 1" is approx 13-15 characters is the quickest and least complicated. agreed?

Jeremy, you're the Original Poster, so what you want is what matters. however, if you just wanted a way to do a guesstimate you didn't need to post a question here. you simply haven't yet explained the problem sufficiently for us to come to a technical solution. questions:
  • Is this just for your personal use, or is it for the use of a number of people who all use macs?
  • would you prefer to drag your files to a droplet, use a menu item to select them, run an application?
  • do you want the script to upload the files, or just check to see if it will work?
  • what do you want the script do if it finds a file that will be too long? skip it, skip the whole move, rename the file?
gotta specify what you want before we can give it to you

jeremyoliver 05-26-2009 03:13 PM

* Is this just for your personal use, or is it for the use of a number of people who all use macs?
- 4 designers, we see the server shortcut on our macs. We drop files there. We want to check if the file path character count is more than 250 characters. on our macs, before transferring.

* would you prefer to drag your files to a droplet, use a menu item to select them, run an application?
- just drag and drop the files in a design folder we have on the server.

* do you want the script to upload the files, or just check to see if it will work?
- count the file path characters.

* what do you want the script do if it finds a file that will be too long? skip it, skip the whole move, rename the file?
- nothing. we'll fix them ourselves if they're too long.

thanks for the help.

tw 05-26-2009 05:08 PM

ok, well you can't just drop the files on the server folder - once you start the transfer to the windows machine, the process is out of the Mac's hands. what you'll need to do instead is drop the files on a droplet which checks their lengths. so do this:
  1. open Script Editor and copy/paste the following script into it
  2. save the script as an application
  3. move the application to the desktop, place it in the dock, put it in the script menu, or all of the above. eventually you'll want a copy of this script on each Mac.
  4. when you want to transfer files, drag and drop them onto this droplet, or select them in the finder and run the droplet from the script menu. if it's all clear, it will give you the option (which needs debugging) of moving the files to the server automatically, if there are issues it will give you the local (Mac) paths of the files that will go over the limit.
Code:

property serverBasePath : "E:"
-- or whatever the base path on the Windows machine is
property mountedDiskName : "E"
-- or whatever name the server disk appears as on the desktop
property maxLength : 255

global tooLong

on run
        tell application "Finder"
                set theItems to selection as alias list
        end tell
        mainLoop(theItems)
end run

on open theItems
        mainLoop(theItems)
end open

on mainLoop(theItems)
        set tooLong to {}
        repeat with thisItem in theItems
                checkLengths(thisItem as text)
        end repeat
        if tooLong is not {} then
                set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
                set tooLongList to tooLong as text
                set AppleScript's text item delimiters to tid
                tell application "Finder"
                        activate
                        display alert "Path Length Warning" message "The following folders and/or files will produce paths of more than " & maxLength & " characters on the Windows server.  Please fix." & return & return & tooLongList as warning
                end tell
        else
                tell application "Finder"
                        activate
                        display alert "Path Length Warning" message "This transfer should work correctly.  Move files to server?" as informational buttons {"Quit", "Move Files"} default button 2
                        if button returned of the result is "Move Files" then
                                move theItems to disk mountedDiskName
                        end if
                end tell
        end if
end mainLoop

to checkLengths(theItem)
        set itemInfo to info for alias theItem
        set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
        set baseFolderCount to (count of text items of (theItem)) - (folder of itemInfo as integer)
        set AppleScript's text item delimiters to tid
        iterate(theItem, baseFolderCount)
end checkLengths

to iterate(theItem, baseFolderCount)
        set itemInfo to info for alias theItem
        set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
        set serverPath to serverBasePath & (text items baseFolderCount thru -1 of theItem)
        set AppleScript's text item delimiters to "\\"
        set serverPath to serverPath as text
        set AppleScript's text item delimiters to tid
        if length of serverPath > maxLength then
                set end of tooLong to theItem
        else
                if folder of itemInfo is true then
                        display dialog theItem
                        tell application "System Events"
                                set theItems to (get every disk item of folder theItem whose visible is true)
                        end tell
                        repeat with thisItem in theItems
                                iterate(thisItem as alias as text, baseFolderCount)
                        end repeat
                end if
        end if
end iterate

This probably will need tweaking - experiment a bit with some throw-away copies of files, and let us know what needs to be revised.

jeremyoliver 05-27-2009 10:13 AM

Thanks tw.

So, I pasted the code into script editor, saved it as an application on my desktop. Dragged a working folder that I want to upload (one that has less than 255 character paths for sure) and this pops up:
http://i426.photobucket.com/albums/p...eroliver/1.jpg

I click OK, then this pops up:
http://i426.photobucket.com/albums/p...eroliver/2.jpg

I click "OK" and nothing happens. So I tried it again and clicked "edit", it opened the app in script editor.

So, I assumed this meant the character length was <255 characters. (I didn't see any indication it was less or more but I knew this particular folder path was <255 characters.)

Next, I created an extremely long file path with definitely more than 255 characters and I got the exact same pop ups:
http://i426.photobucket.com/albums/p...eroliver/3.jpg

I tried just clicking the script editor created application as well and I got this:
http://i426.photobucket.com/albums/p...r/Picture5.png

I don't understsand this. I didn't select any folder, it never gave me a chance to select any particular folder.
If I select "move files" I get this:
http://i426.photobucket.com/albums/p...r/Picture6.png

I don't need the script to move the files anywhere. I'll copy them over once I know there isn't any file paths in the folder that exceed 255 characters.

tw 05-27-2009 10:27 AM

that's because I left a debugging line in the script - 10 lines from the bottom, says display dialog theItem. you can delete that line (moderators, if you see this, please remove that line from the code above - I can't edit it for some reason). sorry, always doing things like that.

if you don't even want the option to move stuff, then change this section:
Code:

        display alert "Path Length Warning" message "This transfer should work correctly.  Move files to server?" as informational buttons {"Quit", "Move Files"} default button 2
        if button returned of the result is "Move Files" then
                move theItems to disk mountedDiskName
        end if

to read:
Code:

        display alert "Path Length Warning" message "This transfer should work correctly." as informational
I just thought it would be a convenience. :)

jeremyoliver 05-27-2009 02:27 PM

I altered both sections of the code you mentioned, however I get exactly the same messages except for the move files option. :S

tw 05-27-2009 02:34 PM

is this machine running Tiger or Leopard?

tw 05-27-2009 02:47 PM

ah, never mind. change this bit of code (about 9 lines from the bottom):
Code:

tell application "System Events"
        set theItems to (get every disk item of folder theItem whose visible is true)
end tell
repeat with thisItem in theItems
        iterate(thisItem as alias as text, baseFolderCount)
end repeat

into this:
Code:

tell application "System Events"
        set theItems to (get every disk item of folder theItem whose visible is true)
        repeat with thisItem in theItems
                set thisItemPath to path of thisItem
                my iterate(thisItemPath, baseFolderCount)
        end repeat
end tell

system events is a picky sucker sometimes.

jeremyoliver 05-27-2009 04:18 PM

sweeeeet. Works perfect. thanks a lot tw.


All times are GMT -5. The time now is 07:26 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.