Powershell Get-childItem: The specified path, file name, or both are too long.

Hey Scriping Guys!
I've been using a PowerShell script for a couple of years now to generate a monthly report showing the size of user folders on a number of departmental file servers.  It's working just fine on all file servers except one where the users have gotten carried away with creating sub-folders and using realy long descriptive file names.  The problem piece of script is this:
$colItems = (Get-ChildItem \\192.168.10.5\marketing -recurse | Measure-Object -property length -sum)
"marketing-serv\marketing: "+"{0:N2}" -f ($colItems.sum / 1GB) + " GB"
The reply I get is:
Get-ChildItem : The specified path, file name, or both are too long. The fully
qualified file name must be less than 260 characters, and the directory name mu
st be less than 248 characters.
At G:\data\Server_space_Report\serverspace2.ps1:37 char:27
+ $colItems = (Get-ChildItem  <<<< \\192.168.10.5\marketing -recurse | Measure-Obje
ct -property length -sum)
Yes, the message is correct, however, when I connect to the server, right click the folder and chose properties it returns a size of 128 GB.  My questions are
1. Why does clicking on folder properties not produce an error (what is it doing differently from my script)?
2. How can I fix my script?
Thanks,

I am trying to clear up the older open posts on this forum. If this is still an unresolved issue for you please let me know. If you do not post back within one week I will assume it is resolved and will close this thread.
Thank you
Ed Wilson
Microsoft Scripting Guy

Similar Messages

  • Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

    Hi, Im trying to get the whole path in my server, so i tried that with this following code
    Get-ChildItem $sourceFolder  -Recurse | ?{$_.PsIsContainer} |Get-Acl
    But then, it showed me somtehing like this :
    Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
     I tried to find the solver everywhere and mostly they propose to change the path name, which is impossible, since I am working with my company server, and those folder have already there before i start to work here, then the other ask me to use robocopy,
    but all of the trick just dont work
    is there any way to solve this problem? thanks

    There is no simple solution to this. And it is not a limitation of powershell itself, but of the underlying NTFS file system.
    If the problem is that a folder with a name longer than 248 exists anywhere within your directory structure, you are hooped.
    If the problem is that some fully qualified path names exceed 260 characters, then, in those cases, the solution already given is to create a psdrive partway up the path from the drive letter or server/share root of the path. Unfortunately, the output produced
    will be relative to that psdrive and not to what is specified as the $sourcefolder.
    unless you already know where those problematic paths are, you might consider trying to trap those errors and have your script figure out where it needs to create psdrives. You might then be able to calculate the equivalent path for each file or folder and
    output that. the programming effort would be simpler to just created a psdrive for each folder encountered, however I expect that would be very inefficient.
    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

  • SharePoint 2010, Visual Studio 2010, Packaging a solution - The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

    Hi,
    I have a solution that used to contain one SharePoint 2010 project. The project is named along the following lines:
    <Company>.<Product>.SharePoint - let's call it Project1 for future reference. It contains a number of features which have been named according
    to their purpose, some are reasonably long and the paths fairly deep. As far as I am concerned we are using sensible namespaces and these reflect our company policy of "doing things properly".
    I first encountered the following error message when packaging the aforementioned SharePoint project into a wsp:
    "The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."
    I went through a great deal of pain in trying to rename the project, shorten feature names and namespaces etc... until I got it working. I then went about gradually
    renaming everything until eventually I had what I started with, and it all worked. So I was none the wiser...not ideal, but I needed to get on and had tight delivery timelines.
    Recently we wanted to add another SharePoint project so that we could move some of our core functinality out into a separate SharePoint solution - e.g. custom workflow
    error logging. So we created another project in Visual Studio called:
    <Company>.<Product>.SharePoint.<Subsystem> - let's call it Project2 for future reference
    And this is when the error has come back and bitten me! The scenario is now as follows:
    1. project1 packages and deploys successfully with long feature names and deep paths.
    2. project2 does not package and has no features in it at all. The project2 name is 13 characters longer than project1
    I am convinced this is a bug with Visual Studio and/or the Package MSBuild target. Why? Let me explain my findings so far:
    1. By doing the following I can get project2 to package
    In Visual Studio 2010 show all files of project2, delete the obj, bin, pkg, pkgobj folders.
    Clean the solution
    Shut down Visual Studio 2010
    Open Visual Studio 2010
    Rebuild the solution
    Package the project2
    et voila the package is generated!
    This demonstrates that the package error message is in fact inaccurate and that it can create the package, it just needs a little help, since Visual Studio seems to
    no longer be hanging onto something.
    Clearly this is fine for a small time project, but try doing this in an environment where we use Continuous Integration, Unit Testing and automatic deployment of SharePoint
    solutions on a Build Server using automated builds.
    2. I have created another project3 which has a ludicrously long name, this packages fine and also has no features contained within it.
    3. I have looked at the length of the path under the pkg folder for project1 and it is large in comparison to the one that is generated for project2, that is when it
    does successfully package using the method outlined in 1. above. This is strange since project1 packages and project2 does not.
    4. If I attempt to add project2 to my command line build using MSBuild then it fails to package and when I then open up Visual Studio and attempt to package project2
    from the Visual Studio UI then it fails with the path too long error message, until I go through the steps outlined in 1. above to get it to package.
    5. DebugView shows nothing useful during the build and packaging of the project.
    6. The error seems to occur in
    CreateSharePointProjectService target called at line 365 of
    Microsoft.VisualStudio.SharePoint.targetsCurrently I am at a loss to work out why this is happening? My next task is to delete
    project2 completely and recreate it and introduce it into my Visual Studio solution.
    Microsoft, can you confirm whether this is a known issue and whether others have encountered this issue? Is it resolved in a hotfix?
    Anybody else, can you confirm whether you have come up with a solution to this issue? When I mean a solution I mean one that does not mean that I have to rename my namespaces,
    project etc... and is actually workable in a meaningful Visual Studio solution.

    Hi
    Yes, I thought I had fixed this my moving my solution from the usual documents  to
    c:\v2010\projectsOverflow\DetailedProjectTimeline
    This builds ok, but when I come to package I get the lovely error:
    Error 2 The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. C:\VS2010\ProjectsOverflow\DetailedProjectTimeline\VisualDetailedProjectTimelineWebPart\Features\Feature1\Feature1.feature VisualDetailedProjectTimeline
    Now, the error seems to be related to 
    Can anyone suggest what might be causing this. Probably some path in an XML file somewhere. Here is my prime suspect!
    <metaData>
    <type name="VisualDetailedProjectTimelineWebPart.VisualProjectTimelineWebPart.VisualProjectTimeline, $SharePoint.Project.AssemblyFullName$" />
    <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
    </metaData>
    <data>
    <properties>
    <property name="Title" type="string">VisualProjectTimelineWebPart</property>
    <property name="Description" type="string">My Visual WebPart</property>
    </properties>
    </data>
    </webPart>
    </webParts>
    .... Unless I can solve this I will have to remove the project and recreate but with simple paths. Tho I will be none the wiser if I come across this again.
    Daniel

  • TFS Build Error - Exception Message: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters

    I am trying to set-up CI of Orchard CMS and deploy it on Azure using TF service. I am stuck at following error for path being
    longer than 260 characters. However, when counted the total characters in path are 235. Please see the below error :
    Other Errors and Warnings
    1 error(s), 1 warning(s)
    Exception Message: TF400889: The following path contains more than the allowed 259 characters: drop/_PublishedWebsites/Orchard.Web_Package/Archive/Content/C_C/a/src/projects/Orchard/dev/DevAltaf/Orchard/src/Orchard.Web/obj/Debug/Package/PackageTmp/Modules/BrentApart.BannerManager/Scripts/controllers/bannerAssignmentController.js. Specify a shorter path. (type VssServiceException)
    Exception Stack Trace: at Microsoft.TeamFoundation.Build.Workflow.Activities.FileContainerDropProvider.EndCopyDirectory(IAsyncResult result)
    at Microsoft.TeamFoundation.Build.Workflow.Activities.CopyDirectory.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
    at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
    Inner Exception Details:
    Exception Message: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. (type PathTooLongException)
    Did anyone came across such issue while deploying Orchard on Azure with TF service? If yes, how did you sort this freaking error?
    Thanks,
    Altaf B.

    Hi AltafB,
    For your situation, you can short the path for the source code. Or use a short path for build agent folder in your build definition. You can refer to the links below to solve your problem:
    http://blogs.msdn.com/b/aaronhallberg/archive/2007/06/20/team-build-and-260-character-paths.aspx
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/1638a5f0-9321-4ff9-9ee7-6d347badb972/please-some-solution-to-the-specified-path-file-name-or-both-are-too-long?forum=tfsbuild
    Besides, since you deploy Orchard to Azure, you can also publish it directly using publish profile in Visual Stduio or WebMatrix directly.
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

    I've followed
    this blog post, but it didn't work for me. I truly don't want to change my solution path as this is not acceptable. What else can I do?
    I can't believe we still have limits on path length.

    Note that the solution described in the blog post does not change your solution path. The _CSRUN_STATE_DIRECTORY environment variable sets the location of the temporary folders used by the compute emulator. Your solution does not need to move.
    Though, you may still have problems related to path length inside your solution. To resolve these, I have sometimes used symbolic links (using MKLINK /D link target) or substed drives (SUBST X: path) to create shorter paths and then opened the
    solution from there. If I recall correctly, with the first method, you need to be careful how you navigate to the solution in the Open Project dialog. I think that if you browsed to the path, it would still use the long path, so you need to paste the short
    path into the file name text box to go directly to the location of your .sln file. I may be misremembering the details though.
    BTW, I can't believe we still have limits on path length either.

  • Install iTunes 10.4.1 install error - The Folder Path "File Name" contains an invalid character

    Upgraded computer from XP Prof 32-Bit to Windows 7 Ultimate 64-Bit (Upgrade package, performed Custom Install).
    Attempt to install iTunes 10.4.1 for 64-Bit.  Receiving the following error/problem:
    The Folder Path "File Name on my external drive" contains an invalid character
    I click ok and then get this:
    The Installer encountered errors before iTunes could be configured.  Errors occurred during installation.  Your system could not be modified,  Please run the installer again, or click Finish to exit.
    Any fixes for this?

    Sorry, one of us is not managing to be clear enough.
    Does the message read The Folder Path "File Name on my external drive" contains an invalid character or perhaps The Folder Path "<some path name here>" contains an invalid character?
    If so, then the problem might be just what it says it is with the path name in question... Either way if you list the path given in the error message in a reply to this thread it might provide a clue for anyone tying to help with the problem.
    You could try downloading the installer to C:\iTunesSetup.exe in case that helps.
    tt2

  • I am using itunes 10 and trying to consolidate my files.  I keep getting the error "Copying files failed.  The file name was invalid or too long".  How can I indentify what file is causing this problem or resolve this issue?

    I am using itunes 10 and trying to consolidate my files.  I keep getting the error "Copying files failed.  The file name was invalid or too long".  How can I indentify what file is causing this problem or resolve this issue?

    BUMP
    Yes, I just get that message. I don't see how I could investigate this problem.
    I didn't mention that this happened when I was consolidating my library, not copying files to another computer.
    In other words, I'm using a "normal" itunes procedure, itunes won't complete it, and won't tell me exactly why or how to figure out how to fix it...
    Is there at least some easy way to tell which files were successfully copied to my itunes music folder so I can work on moving the uncopied files?
    Can anybody help me?

  • ITunes v10.6.1.7 "Copying files failed. The File name was invalid or too long."

    I'm trying to organize my music files using iTunes 10.6.1.7 and I keep getting the error message "Copying files failed. The File name was invalid or too long."
    I've got music folders by artist in both the iTunes Music folder and the iTunes Media/Music folder. When I add certain files by drag/drop they sometimes get lost and I don't want that to happen anymore. I used to just consolidate my music files using the File/Library/Organize Library option and that worked, however now when I do that, I get the error message.
    I'm a novice and the only online stuff I see is both confusing and refers to earlier versions of iTunes.
    My concern is that I have heard that people lose entire libraries of their music when they trry to fix things like this and I don't want that. If this is of any importance, I have several files called iTunes library and temp library. I have no idea what that all means but I'm scared to death of it.
    Also, I can't get to the "re-organize library" link at all. It won't let me.
    One thing that be of some interest is that when I pull up the properties of the music and media/music files they are marked "read only" I'm also afraid to touch that!
    Please help and please know that I am a dummy. Be kind and be clear. Step by step would be great, with images even better. Thanks.

    Perhaps nobody knows the answer? We're fellow users here answering questions in our free time when we think we've something useful to contribute.
    You can choose to *Consolidate selected tracks* with a right-click menu. Perhaps if you can identify a specific track that won't consolidate and examine the full path to the file & the path that iTunes would create when it consolidates the problem might become apparent. For example iTunes may not be able to move files if the source or destination path length exceeds 255 characters.
    tt2

  • Itunes for WIN7: attempting to copy to disk "..." failed.  The file name was invalid or too long

    itunes for WIN7: attempting to copy to disk "..." failed.  The file name was invalid or too long
    help!!

    Max. path length is 255 characters, or perhaps there are some non-displaying characters hidden there. Try dropping a song you want to add to iTunes into the Automatically to iTunes folder to see if that works any better.
    tt2

  • HT1751 Consolidating files failed.  The file name was invalid or too long.  How to trouble shoot this?

    I am trying to move my iTunes library from old XP PC to Windows 7 PC, using an external hard drive.  Using tutorial and signed in as administrator.  Trying to consolidate my library and receive error message " Copying files fail. The file name was invalid or too long".    Don't know what to do as next step.   The library is sitting on the hard drive under the Administrator ID (My Documents\My Music\iTunes\iTunes Music).  
    Any thoughts?

    You can select a group of tracks and consolidate from the right-click context menu. You coud try consolidating in batches, say all songs by artists beginning with A, then B, etc, then the other media types, until you can isolate a problem track and then try moving that by hand and fixing the broken link.
    I also have two scripts that could help you, Unconsolidated and ConsolidateByMoving. The first can make a playlist of all unconsolidated tracks, the second can consolidate a selection of tracks by moving them instead of copying.
    tt2

  • Copying music failed. The file name was invalid or too long.

    I went to consolidate my music, but when it got about 2/3 of the way through, it stopped with the error message, "Copying music failed. The file name was invalid or too long." I don't know which file it is referring to. How do I find this out?
    I needed to cosolidate so I could backup the entire library to DVD. Now I'm left with two partially complete libraries with many duplicates.

    To find out which file it was, look at where you were
    copying them too and see which was the last file
    copied - and then go back to your source, and go to
    the next one - it should be that one.
    I just wanted to add that I had the same issue (failure to finish copying and "invalid or too long" error msg) and at first didn't see how looking for the last file copied would work since iTunes is copying into folders.
    Duh.
    Reverse sort by date modified (newest folder at the top of the list) then drill down to the folder containing the files being copied. Voila. There was the (missing) culprit, and I knew which file to rename in the source folder.
    Thanks for the kick in the brain pan.
    Sony VAIO PCG-V505ACP Windows XP Pro

  • HT1751 I did all of the above and at the "Consolidate files" screen I clicked "ok" then it sayd "copying files failed. the file name was invalid or too long" and I had to click "OK"  I cannot consolidate the files to transport  to my external harddrive -h

    I would like to backup my itunes to my external hard drive
    I did all the steps up to "organize Liberary" which at this point I checked the box and the clicked"ok"
    it then said "copying files failed.  The file name was invalid or too long" "OK"
    It will  not let me consolidate the files so I can transfer to my external hard drive
    what am I doing wrong - any suggestions?
    thanks,

    Are you using consolidate files to bring in stray files to your main iTunes Media folder before backing up, or to copy the media folder to the external drive as part of backing up? If it is the latter then you are taking the wrong approach. See this user tip.
    Run my script Unconsolidated on the library. It will show you the remaining unconsolidated files which might give a clue as to which files iTunes is having a problem with. You can consolidate selected files in batches (select, right-click) as opposed to trying to do everything in one go. Alternatively you could try moving the remaining unconsolidated files with ConsolidateByMoving as long as this step is a precursor to a backup..
    tt2

  • HT1751 Consolidating ITunes Library Failed - message received: "Copying files failed. The file name was invalid or too long" . Please help - how to i fix this issue?

    I consulted your website for details on how to back up my ITunes Library on my PC-found the article very helpful-I reached step 7 - clicked ok and the following message came up: "Copying files failed. The file name was invalid or too long."  Please can you help and advise what I should do or how to fix this issue.   My pc operating system is Windows 7 Home Basic

    You can select a group of tracks and consolidate from the right-click context menu. You coud try consolidating in batches, say all songs by artists beginning with A, then B, etc, then the other media types, until you can isolate a problem track and then try moving that by hand and fixing the broken link.
    I also have two scripts that could help you, Unconsolidated and ConsolidateByMoving. The first can make a playlist of all unconsolidated tracks, the second can consolidate a selection of tracks by moving them instead of copying.
    tt2

  • The iphone .... cannot be synced.The file name was invalid or too long.

    the iphone .... cannot be synced.The file name was invalid or too long.
    wat can i do to sync my iphone

    Hi there rohitnitin,
    It looks like the article below addresses the error message you are describing.
    iTunes: Unable to sync photos
    http://support.apple.com/kb/TS3697
    -Griff W.

  • "The file name was invalid or too long" appears when I try to copy music form a CD to my computer using Windoww XP

    "The file name was invalid or too long" appears when I try to copy music from a CD to my compu
    ter using Windows XP

    Go to the songs view sorted as Album by Artist. Select, for example, the songs of artists whose names begin A-E. Right-click and click consolidate files. Assuming this group consolidate without error move on to another group, say F-J. If there is an error divide the original group into smaller chunks until you can isolate which tracks are causing a problem.
    tt2

Maybe you are looking for