If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Check if path + filename exceeds 255 chars
Hi You can try Long Path tool , and hope it can help, tnx
On Sunday, January 14, 2007 6:23:17 AM UTC+8, wrote: Hi. A post with a similar name was started in this group a year or so back, but I thought I'd put this in a new thread... I recently setup a dedicated hard drive for making regular backups for a large number of files (well, over 20gb anyways). The computer is currently running Win2k, and will soon use XP. The main drive and the backup drive are formatted using NTFS. The first time I tried to copy my files to the backup drive, I got an error: "Error Copying File or Folder" - "Cannot copy file: The filename you specified is invalid or too long. Specify a different filename." Since the copy window itself was still showing the last filename, it was obvious which files were causing problems. However, manually changing each offending file would be a complete pain -- it sometimes took 20 minutes for an error to come up. Then, the WHOLE copy process was aborted, and I'd have to fix that one file, and then try again. With hundreds of offending files (or more), this could have taken weeks. None of the offending files had invalid characters anywhere in their paths. Also, none of the filenames were long at all. It was purely the *LENGTH* of the *PATH* that was causing problems... There were lots of nested folders. So of course I started searching about the issue on google... It kind of ****ed me off that Windows would let me *create* files whose paths were so long (no warnings in Win2k), but would then choke up on copying them. I found that this was a known issue. NTFS can handle *VERY* long path names using special Unicode based file access methods. However, many programs (including some operating system routines -- apparently the explorer COPY routine!) still use methods which limit the path length to 260 characters (includes a trailing null termination). Lots of people were having problems *deleting* files whose path lengths were too long. And of course, some people had the same problem as me -- making backups. Anyways, since making these backups was really important to me, I spent half a day trying to figure out a good solution... I thought I'd post my results here. Hopefully it'll help someone down the line !! ********** ********** TO FIND FILES WHOSE PATH LENGTH IS VERY LONG ********** ********** There are some utilities which automatically *rename* files whose *filenames* are very long. These are mostly used for people who want to burn a folder onto a CD using ISO 9660 or some similar standard. I didn't want something like that. I wanted a way to simply get a *LIST* of all the files whose *path* names were greater than 260 characters (259 if the null termination character is excluded). Then I can manually go down the list and rename any offending files. I know it's tedious, but I don't want some program lopping off parts of my file and folder names according to some arbitrary rules. Especially when web pages are involved... In reality, I only found one program that *could* do that if I wanted it to, so it's a non-issue. About the last comment: While I found lots of programs to list files with long filenames, most of them ignored the complete path name. This was the number-one feature I was looking for... The methods and programs/utilities I found on the web are listed below: Method 1 - dir to find offending files ---------- Except for really young people, I think even most non-techie people have used the "dir" command in DOS at one time or another. It provides a really easy way to solve this particular problem, but for some reason, I would never have thought of it if someone else hadn't suggested using it. You can just use some parameters to force it to output *only* the path + filename + extension, one per line. You also (probably) want it to traverse all subdirectories on a given hard drive. And of course, you want to pipe the output to a file, rather than displaying it on the screen. Once you have this file (and this method takes only a second), you can use whatever method you like to search for lines containing more than 255 (or however many) characters. Method 1a - example ---------- dir c:\ /s /b | sort /+256 /r LongName.txt Type that into a command prompt, then open up LongName.txt in your favorite text editor. It will contain a list of all the files on your hard drive (as typed above, c:\ only), sorted by the length of their path names. If you want, you can just manually count the number of characters per line, and see which ones are greater than 259 characters. Or, use a nice text file utility to do the counting for you. Method 1b - dir using SED ---------- Same as above, but using a standardized library called "SED" for post-processing. Credit goes to Bjorn Simonsen. Use the following batch script: VLFN.cmd (or VLFN.BAT, works the same) --------------cut below ------------- IF EXIST max_path_warning.txt DEL max_path_warning.txt pause DIR c: d: /B /S | SED -n '/^.\{255\}/p' max_path_warning.txt START max_path_warning.txt --------------cut above ------------- The "pause" line can be removed, and you might have to fiddle with single quotes versus double quotes. You need to download SED from one of the following: http://www.student.northpark.edu/pemente/sed/ http://sed.sourceforge.net/ Method 1c - dir using gawk ---------- Type the following in a command prompt: dir /b /s | gawk "{if (length($0) 255) print $0 \" (\" length($0) \" chars)\"}" longfiles.txt You need to have a Windows version of gawk installed (search google). Method 1d - dir using other utilities ---------- Other utilities: - ORTXL from http://home.mnet-online.de/horst.muc/ - SPF, SPFPC Method 2 - CutLongNames.exe to find offending files ---------- I put this in it's own category because it's the ***ONLY*** premade user-friendly utility I could find to do the job. I searched for half a day and didn't find any alternatives that actually did what I needed. There are lots of utilities that find *filenames* longer than 255 (or however many) characters. A lot of them will even automatically rename such files according some rule. But I didn't find anything that worked for long *path* names. This does. It's free too (some of their other software, like "Useful File Utilities," is not free, but this one is)... http://www.replsoft.com/cutlongnames.html The biggest feature it lacks is the ability to search *only* a specific folder. This program only lets you search entire drives. It's still very useful. You can map a folder to a virtual drive letter if you really want to search only a specific folder (see "net use" command). Also, it would be nice if the program could save a list of the offending files to a txt file. Method 3 - Other utilities to find offending files ---------- Some utilities that can search for long *filenames* (but maybe not *path* names): - Siren - The Renamer - Multirename - 1-4a Rename - DCSoft Long Filename Finder I haven't personally tried these ones, I found the names in a newsgroup post from alt.comp.freeware (great thread!!) You could probably find a whole slew more from download.com or a google search... Method 4 - Scandisk ??? ---------- I have no idea if this works. If you're running Win9x with a FAT32 drive, maybe you can use scandisk to find files whose pathnames are too long. I don't know if the problem even **exists** for FAT32 drives... Can you even create a file with such a long pathname on FAT32??? As far as similar utilities for Win2k, XP, etc: I've heard that chkdsk does *not* offer any help. Method 5 ---------- This seems to be made just for filenames, but I included it anyway. Credit goes to "Pegasus (MVP)": Batch file: @echo off setlocal EnableDelayedExpansion for %%a in (*.*) do ( set name=%cd%%%a if not "!name:~253,1!"=="" echo Excessively long name: %%a ) endlocal If you run this batch file from your the folder to be examined then it will flag excessively long file names. Note that it won't process files names that contain certain special symbols such & (e.g. P&Q.txt). ********** ********** TO COPY FILES WHOSE PATH LENGTH IS VERY LONG ********** ********** If you want to be stubborn and try to keep the files as they are, or if you don't have permission to rename other people's files, these methods might still let you make a backup... Method 1 ---------- Use a special (proprietary) backup program. Method 2 ---------- Use a zip/rar program, and save the archive to the backup drive. Method 3 - Copy utilities which even copy offending files, or at least skip them ---------- The standard windows copy completely aborts when it encounters a file whose pathname is too long. If you're doing a huge copy (like backups), you might have to wait 20 minutes before getting an error, then have to start all over again. There is no "skip and continue" option. The following programs may either skip offending files, or possibly even manage to copy them (still have to try): - xxcopy - robocopy - ZTree Bold - KillCopy - LBACK Method 3a - using xcopy ---------- Found this snippet from a forum posting, credit goes to "CrazyOne": xcopy /e/h/k/c/y/r C:\*.* D:\ C:\WinCopy.txt 2&1 C is the source drive and D is the destination drive. If your letters don't correspond to these then use the appropriate letters. The above command will write to a text file and in it you will see which files it did not copy. This does not mean they are all files with invalid lengths but you can at least check them out. xcopy /e/h/k/c/y/r C:\*.* D:\ C:\WinCopy.txt 2&1 C is the source drive and D is the destination drive. If your letters don't correspond to these then use the appropriate letters. The above command will write to a text file and in it you will see which files it did not copy. This does not mean they are all files with invalid lengths but you can at least check them out. ********** ********** TO DELETE FILES WHOSE PATH LENGTH IS VERY LONG ********** ********** Method 1 - Map deep directories to a virtual drive letter ---------- I believe you can do this with the "net use" command, but I haven't looked into this much. There are lots of freeware utilities which do this, search download.com. You might need to do this, for example, to delete a temporary file or an IE favorite (sometimes web page titles can be excessively long). Method 2 ---------- Use the command line to delete the offending file(s), using short filenames (8.3) if needed. |
Ads |
Thread Tools | |
Display Modes | |
|
|