![]() |
Count Path Characters before upload to server
I need to be able to count the number of characters in my longest file paths before I upload the folders to my server. My limit is 255. I'm not sure if I reach that amount however I'd like to start checking each folder before I upload to avoid any issues in the future. How do I do this in osx?
thanks. |
I guess you could write a shell script that parses the amount of characters in the full path and if it is under 255 it can rysnc but if over it will error out?
I am not sure exactly how to count out characters in a path though. I guess I would start with the cd command and then maybe the pwd command but how to count the characters from there is escaping me at the moment. I am sort of a novice scripter though. and of course I figure out a way to do it right when I hit post... Code:
|
sorry, what do I do with that code? copy and paste it into terminal? I'm obviously clueless when it comes to scripting.
|
Hmm, OK, well is this network share already mapped? Or are you mapping it or how is it set up?
The code I posted will just print the amount of characters in the current directory you are in. So if you are in /Users/jeremyoliver/documents, and you run that command it will print the number of characters in that file path. To script it you would have to add a few lines, it seems simple enough and perhaps I can actually help you do it. I just would need some more info. |
how are you uploading the files? though applescript, a shell script, an ftp app? and when you say that the 'file path' can only be 255 characters, do you mean the 'actual' file path can't be more than 255 characters (including the folder heirarchy? this seems unlikely), or do you mean that the file name itself cannot be more than 255 characters?
|
You could use my "reportLongPaths" script: http://hayne.net/MacDev/Perl/reportLongPaths
Sample usage: reportLongPaths 100 ~/Documents If you aren't familiar with running scripts in Terminal, see this Unix FAQ |
thanks for the reply everyone. Here's the reply from my IT guy when I asked him if file name length was an issue I should be conscious of. I have access to our server from My mac and I just drag and drop files into a folder titled "creative". The file name length doesn't seem to be an issue, it's the total character count of the file path.
"The maximum file path length is 255 characters on a Windows server. For example, if you make a subfolder in the creative folder, the path length is already 17 because on the server it appears as “E:\DATA\Creative\”. So any files in this directory must be 238 characters or less. The more subdirectories you have, the shorter the filename can be. In the end, all of the characters in the subfolders to reach the file, plus the characters in the filename must be less than 255. We have seen this issue before when one of our clients went nuts with the amount of subfolders they had. It causes tons of issues, files can’t be accessed, backed up, or even deleted. It was a huge nuisance. You are the first person to ever proactively ask this question. I really appreciate it because in the end you are saving (wasteful) maintenance time on the server, and saving money. Nice……." |
Quote:
Windows. You're great-grandfather's OS. This is going to be a bit tricky because it's the destination path that can't be more than 255 characters, not the source. That means you need to add the number of characters in the destination folder path to the number of characters in the file name and keep that below 256. |
try this droplet. open the Script Editor, paste the following code in, and save it on the desktop as a script application. it will show up as a droplet, and you can drag files and folders onto it. it should check through all of the files folders and calculate whether the new filepath length will go beyond 255 chars, and alert you if one does. uncomment the 'display alert' line to test it; uncomment the 'tell application "Finder" to move...' line once you've set the correct path the the server folder and you want to start moving things.
I haven't tested it beyond basic functionality though. Code:
property serverPathLength : 17 |
You could also have launchd watch the path and any time a file or folder it put into that path it can execute a script.
|
Quote:
|
Quote:
Just set launchd to watch the specified path and whenever the path is modified it can execute a script. You may have to do some wild carding and loops to make sure it hits every sub folder but I think it may be worth a shot if this is really an issue. Of course it is is a multi user issue you would want the server to run it and perhaps set up some sort of ACLs so that a system daemon can watch that path. I don't have any Windows servers that are part of my Mac infrastructure at work so I have never needed to file share really where a Mac was writing files to a Windows box. All the files I need the Macs to hit are for read only purposes. |
Doesn't the script need to run before the file is copied to the server? If the file path is too long, it's already to late when it gets there.
|
Damn this is confusing....
What I've been doing so far is using the finder 3 column view, select the file in the deepest sub folder and estimate the amount of characters in the file path. 1" is approx 13-15 characters. lol. I haven't found any file paths that are even close to 200 characters long. I know this seems tedious but I'm completely lost with regards to the suggestions posted above. |
Quote:
You could even set up a launchd item that just periodically scans that directory and anything over the limit it moves to a "move this" folder. |
What I meant was that you need to determine that it's going to be over 255 before it gets moved to the Windows side because if it is and it gets moved, you're going to have problems.
|
Quote:
|
I think I misunderstood how the script works. I thought it was checking the files at their destination. It checks their new path before moving them.
|
Quote:
|
Quote:
|
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.
|
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 |
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. |
Quote:
|
* 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. |
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:
Code:
property serverBasePath : "E:" |
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. |
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 2Code:
display alert "Path Length Warning" message "This transfer should work correctly." as informational |
I altered both sections of the code you mentioned, however I get exactly the same messages except for the move files option. :S
|
is this machine running Tiger or Leopard?
|
ah, never mind. change this bit of code (about 9 lines from the bottom):
Code:
tell application "System Events"Code:
tell application "System Events" |
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.