+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
Windows Thread, Long File and Folder Names in Technical; Hi, Quick question. Is it possible to search for long file names on the network? Some of our staff have ...
  1. #1

    Join Date
    Apr 2007
    Location
    York
    Posts
    551
    Thank Post
    9
    Thanked 4 Times in 4 Posts
    Rep Power
    19

    Long File and Folder Names

    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

  2. #2

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    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)
    Code:
    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
    Last edited by srochford; 7th April 2009 at 10:57 AM.

  3. Thanks to srochford from:

    eejit (7th April 2009)

  4. #3

    Join Date
    Apr 2007
    Location
    York
    Posts
    551
    Thank Post
    9
    Thanked 4 Times in 4 Posts
    Rep Power
    19
    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

  5. #4

    Join Date
    Apr 2007
    Location
    York
    Posts
    551
    Thank Post
    9
    Thanked 4 Times in 4 Posts
    Rep Power
    19
    Just tried the script. Unforuntely it returns items where the PATH is longer than 60 characters rather than just the FILENAME.
    Thanks

  6. #5

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    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 :-)

    Code:
    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

  7. Thanks to srochford from:

    Ignatius (22nd July 2009)

  8. #6

    Join Date
    Apr 2007
    Location
    York
    Posts
    551
    Thank Post
    9
    Thanked 4 Times in 4 Posts
    Rep Power
    19
    Thanks.
    Is it possible to change the folder to drive='C:/Test for example to find names in a specific folder?

  9. #7

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    Everything's possible :-)

    The "execquery" line is using WQL (WMI Query Language; recursive acronyms are great!) and you can add more bits to it.
    Code:
    ("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
    Code:
    ("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:
    Code:
    ("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!

  10. #8
    User3204's Avatar
    Join Date
    Aug 2006
    Location
    Wirral
    Posts
    769
    Thank Post
    55
    Thanked 66 Times in 62 Posts
    Rep Power
    34
    Stupid question possibly, but I don't use this VB scripting much myself.

    Will that keep the file extension, or lose it? IE will "mydumbfilenameisfartoolongtobeanypossibleuseforan ythingatall.doc" become "mydumbfilename.doc" or "mydumbfilenameisfart" ?

  11. #9

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    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)

  12. #10
    eejit's Avatar
    Join Date
    Jun 2005
    Location
    Ireland
    Posts
    606
    Thank Post
    52
    Thanked 12 Times in 12 Posts
    Rep Power
    22
    Nice one Steve.

  13. #11

    Join Date
    Apr 2007
    Location
    York
    Posts
    551
    Thank Post
    9
    Thanked 4 Times in 4 Posts
    Rep Power
    19
    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

  14. #12
    User3204's Avatar
    Join Date
    Aug 2006
    Location
    Wirral
    Posts
    769
    Thank Post
    55
    Thanked 66 Times in 62 Posts
    Rep Power
    34
    Bah, sorry my error, didn't run the script, and assumed it would rename them.. Finding them is fine.. ignore me..

  15. #13

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    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.

  16. #14

    Join Date
    Apr 2007
    Location
    York
    Posts
    551
    Thank Post
    9
    Thanked 4 Times in 4 Posts
    Rep Power
    19
    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?

  17. #15


    Join Date
    Feb 2007
    Location
    51.405546, -0.510212
    Posts
    8,709
    Thank Post
    220
    Thanked 2,615 Times in 1,926 Posts
    Rep Power
    777
    Microsoft's LogParser is another alternative. The following script works perfectly for me, although you may want to change a few things in it.

    Code:
    @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.csv
    See 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.
    Last edited by Arthur; 21st July 2009 at 09:15 PM.

  18. Thanks to Arthur from:

    chazzy2501 (15th March 2010)

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Copy file across variable folder name
    By SimpleSi in forum *nix
    Replies: 11
    Last Post: 10th March 2009, 06:15 PM
  2. Exporting File names from a disc.
    By Neville in forum Windows
    Replies: 2
    Last Post: 25th February 2009, 12:58 PM
  3. Robocopy & long file names
    By cheryl in forum Windows
    Replies: 2
    Last Post: 18th January 2008, 10:27 PM
  4. Student Folder File permissions
    By CM786 in forum Wireless Networks
    Replies: 4
    Last Post: 27th September 2007, 09:28 AM
  5. VBS File takes long time to load 1st time?
    By Samson in forum Scripts
    Replies: 3
    Last Post: 4th September 2007, 07:40 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •