User User name Password  
   
Wednesday 18.9.2024 / 21:21
Search AfterDawn Forums:        In English   Suomeksi   På svenska
afterdawn.com > forums > software, operating systems and more > windows - software discussion > here is a long filename / filepath scan utility
Show topics
 
Forums
Forums
Here is a Long Filename / Filepath Scan Utility
  Jump to:
 
Posted Message
mchampfl
Newbie
_
14. January 2013 @ 12:34 _ Link to this message    Send private message to this user   
I wrote and am using a batch file to scan for long filenames / filepaths. It was inspired by Indochine in his post #514228 "HELP with finding Length of String in BATCH file"

His insight was helpful to me so I thought I would give back. Please note that the one thing that made this batch file 5 times longer to write is the Delayed Expansion concept in variables - ie. !variable! vs. %variable%. I still haven't got it clear when I'm supposed to use which.

I did not go to the effort of being precise about the length of the filename. As it is written, all lengths are +2. For my purposes, a length of 222 is inconsequential compared to 220, or 257 vs. 255, or 300 vs. 298. Also, I have tested this on mapped network drives and it seems to work fine.

Thanks, Indochine, for the idea of writing the filename/path to a file and using the filesize as length.

For the inexperienced, this is a batch file for Windows. You can create the utility by selecting all the text between ===Start=== and ===End=== and pasting it into Notepad. Modify the "set scanroot=c:\" line near the top of the program for the point in the directory tree you want scanned - it will do the entire C: drive as it is written. Then save the Notepad file as something like "lfn.cmd". Then open a command prompt window at the location you saved lfn.cmd and simply type as a command "lfn". When the scan is complete, any filenames/paths longer than the specified length (220 as written) will be listed in the file "lfn.dat" which can be viewed with Notepad.

If these instructions are not clear and simple to you, then you should get someone to help you.


===== Start of Program =============================
@echo off
REM ***********************************************************************
REM ***********************************************************************
REM ***********************************************************************
REM ***
REM *** LONG FILENAME SCAN UTILITY
REM ***
REM ***This batch file will scan the full path of all files from the
REM ***specified folder root looking for long file names, ie. > 255 characters.
REM ***Offending filenames/paths are written to lfn.dat pre-pended with
REM ***their length. The length breakpoint should be set in the range of
REM ***220 chars. Filename/path length is determined by writing the filename
REM ***to a .tmp file and then checking the size of that .tmp file. The filesize
REM ***will always be 2 chars longer due to the CR/LF written with the filepath.
REM ***
REM ***********************************************************************
REM ***********************************************************************
REM ***********************************************************************



setlocal EnableDelayedExpansion
set /a count=0
set /a mod=0
set /a length=0
set /a toolong=0
set /a howlong=220
set scanroot=c:\
set msg=


REM ***
REM ***Delete output file from last session
REM ***
if EXIST lfn.dat del lfn.dat



REM ***
REM ***For each file in the tree from this root...
REM ***Accumulate number of filenames scanned
REM ***mod=0 at every 100th record
REM ***Set fn to the current filename
REM ***Write only the current filename to lfn.tmp
REM ***%a=file parameters of lfn.tmp; ~z of a = file size, which is length of filename +2
REM ***If filename is too long...
REM ***Count it...
REM ***Print the length and current full filename to the end of lfn.dat
REM ***If this is a 100th record...
REM ***Update the screen, showing only the first 50 characters of the current filename
REM ***
for /r %scanroot% %%i in (*.*) do (
set /a count+=1
set /a mod=count%%100
set fn=%%i
echo !fn! > lfn.tmp
for %%a in (lfn.tmp) do (set /a length=%%~za)
if !length! GTR !howlong! (
set /a toolong+=1
echo !length!-!fn!>>lfn.dat
)
if !mod! EQU 0 (
set msg=Scanned:!count! Found:!toolong! !fn:~0,50!
echo !msg!
)
)



REM ***
REM ***Final screen update
REM ***
set msg=Scanned:!count! Found:!toolong! !fn:~0,50!
echo !msg!
===== End of program ==============================




Enjoy!

This message has been edited since posting. Last time this message was edited on 14. January 2013 @ 13:29

afterdawn.com > forums > software, operating systems and more > windows - software discussion > here is a long filename / filepath scan utility
 

Digital video: AfterDawn.com | AfterDawn Forums
Music: MP3Lizard.com
Gaming: Blasteroids.com | Blasteroids Forums | Compare game prices
Software: Software downloads
Blogs: User profile pages
RSS feeds: AfterDawn.com News | Software updates | AfterDawn Forums
International: AfterDawn in Finnish | AfterDawn in Swedish | AfterDawn in Norwegian | download.fi
Navigate: Search | Site map
About us: About AfterDawn Ltd | Advertise on our sites | Rules, Restrictions, Legal disclaimer & Privacy policy
Contact us: Send feedback | Contact our media sales team
 
  © 1999-2024 by AfterDawn Ltd.

  IDG TechNetwork