karldenton Posted April 6, 2009 Posted April 6, 2009 Hi, Quick question. Is it possible to search for long file names on the network? Some of our staff have a habit of pressing save rather than calling it a proper name. These can sometimes cause errors when doing backup to file (rarely). Thanks
srochford Posted April 6, 2009 Posted April 6, 2009 (edited) The script below searches the C: drive on the local computer for files and reports those where the full path is longer than 60 characters - adjust the "C:" and "60" as appropriate. You can run this against a remote computer - just put its name in place of the "." but it would be quicker running it on the server. If you're having problems backing up long files then there are two possible reasons for this; the software is c*&p or the user running the backup process does not have "backup privilege" (Problems with long file names are typically because the server stores something as d:\home folders\year9\student\maths but the user sees that as n:\maths; amongst other things, backup privilege bypasses the length restrictions. If you're using robocopy to run the backup then use it with the /b switch to fix the problem) sComputer="." Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2") set colItems = oWMIService.ExecQuery("select * from CIM_Datafile where drive='C:'") for each item in ColItems if len(item.name)>60 then wscript.echo item.name end if next Edited April 7, 2009 by srochford 1
karldenton Posted April 7, 2009 Author Posted April 7, 2009 Thanks Steve will give this a try this morning. We backup with Windows backup to tape and never have any problems. But once a term of so we copy and paste all the home folders to a folder on a remote computer and it usually kicks up errors with long file names. I've since started using windows backup to backup to remote to the remote pc
karldenton Posted April 7, 2009 Author Posted April 7, 2009 Just tried the script. Unforuntely it returns items where the PATH is longer than 60 characters rather than just the FILENAME. Thanks
srochford Posted April 7, 2009 Posted April 7, 2009 Sorry; that's normally what causes the problem but you can test for the filename length (rather than full path) by checking the length of "filename" rather than "name" - code below. The echo statement shows the full path - you might need to know where the problem file is :-) sComputer="." Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2") set colItems = oWMIService.ExecQuery("select * from CIM_Datafile where drive='C:'") for each item in ColItems if len(item.filename)>6 then wscript.echo item.name, item.FileName end if next 1
karldenton Posted April 7, 2009 Author Posted April 7, 2009 Thanks. Is it possible to change the folder to drive='C:/Test for example to find names in a specific folder?
srochford Posted April 7, 2009 Posted April 7, 2009 Everything's possible :-) The "execquery" line is using WQL (WMI Query Language; recursive acronyms are great!) and you can add more bits to it. ("select * from CIM_Datafile where drive='C:' and path='\\temp\\'") will search c:\temp - note the doubled backslashes You can also search for particular kinds of file - eg ("select * from CIM_Datafile where drive='C:' and path='\\temp\\' and extension='mp3'") would search for MP3s under c:\temp and this would search for mp3 and avi in c:\home\year9: ("select * from CIM_Datafile where drive='C:' and path='\\home\\year9\\' and (extension='mp3' or extension='avi')") watch out for brackets and single and double quotes!
User3204 Posted April 7, 2009 Posted April 7, 2009 Stupid question possibly, but I don't use this VB scripting much myself. Will that keep the file extension, or lose it? IE will "mydumbfilenameisfartoolongtobeanypossibleuseforanythingatall.doc" become "mydumbfilename.doc" or "mydumbfilenameisfart" ?
srochford Posted April 7, 2009 Posted April 7, 2009 Not sure I understand the question. The scripts I've shown won't change anything - they'll simply show you what's there. If you have the extremely long filename then that's what you'll see reported. It's then up to you to decide what to do with it. It's possible for users to create files where the total length of the path on the physical drive plus the filename is too long for explorer etc to cope with but the user sees it with no problem because they start lower down the tree. Once you've found such a long file you can deal with it by just mapping a drive to the lower level folder; explorer will then let you rename the file (if that's what you want to do)
karldenton Posted April 9, 2009 Author Posted April 9, 2009 Steve, Is the syntax of this correct? Don't seem to get any results back and i've put a test file in with a long name: I'm running it on the server and the path for home directories is D:\data\staff. Will it search through all sub-folders in there IE individual staff? sComputer="." Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2") set colItems = oWMIService.ExecQuery("select * from CIM_Datafile where drive='D:' and path='\\data\\staff\\'") for each item in ColItems if len(item.filename)>15 then wscript.echo item.name, item.FileName end if next
User3204 Posted April 9, 2009 Posted April 9, 2009 Bah, sorry my error, didn't run the script, and assumed it would rename them.. Finding them is fine.. ignore me..
mac_shinobi Posted April 10, 2009 Posted April 10, 2009 Must be missing something but in this line of code ("select * from CIM_Datafile where drive='C:' and path='\\home\\year9\\' and (extension='mp3' or extension='avi')") The temp path is not specified so how would that work ? To me it looks like it would search C:\home\year9 for mp3's and avi files.
karldenton Posted April 15, 2009 Author Posted April 15, 2009 Any help on my post above? I'd like to search D:\data\staff for long file names but getting no results using the above code?
Arthur Posted July 21, 2009 Posted July 21, 2009 (edited) Microsoft's LogParser is another alternative. The following script works perfectly for me, although you may want to change a few things in it. @echo off SET PATH=%PATH%;"%ProgramFiles%\Log Parser 2.2" LogParser.exe "SELECT Path, Size FROM D:\*.* WHERE STRLEN(Path) > 200" -i:FS -preserveLastAccTime:ON -o:CSV > Results.csvSee the Log Parser help file for more info (particularly the section called FS Input Format Fields). The amount of things you can do with Log Parser is amazing. Btw, sorry for bumping an old thread but I thought it might be useful. Edited July 21, 2009 by Arthur 1
srochford Posted July 22, 2009 Posted July 22, 2009 Btw, sorry for bumping an old thread but I thought it might be useful. It is useful - learning new stuff is always good and I'd never noticed that log parser can query a file system!
mac_shinobi Posted July 22, 2009 Posted July 22, 2009 Sorry; that's normally what causes the problem but you can test for the filename length (rather than full path) by checking the length of "filename" rather than "name" - code below. The echo statement shows the full path - you might need to know where the problem file is :-) sComputer="." Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2") set colItems = oWMIService.ExecQuery("select * from CIM_Datafile where drive='C:'") for each item in ColItems if len(item.filename)>6 then wscript.echo item.name, item.FileName end if next Could you not do something like this where you have a variable and an inputbox and get it to prompt for how long you want the path for and where drive='C:'" etc use the vbscript browse folder option VBScript Scripting Techniques: Browse Folder Dialog That way you don't have to keep changing the Drive='C:'" etc it will just prompt for length and give you a browse window to browse and select where you want to scan
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now