How to list long file names and paths longer than 260 characters in vbscript?

Hi there,
               I have looked in different posts and forums, but couldn't find an answer to my question.
So, here it is... imagine the small piece of code attached below. I need to be able to iterate and rename recursively (I didn't include the recursive part of the code in order to keep things simple) through files and folders in an user selected path. I thought that by using vbscript FileSystemObject I would be able to do so.
Unfortunately, it seems like the Files method does not detect files whose path is larger than the OS 260 (or 256?) character limit. How could I do it so? Please, don't tell me to use something different than vbscripts :-)
Thanks in advance!
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = FSO.GetFolder(Path)
Set colFiles = objFolder.Files
For Each objFile In colFiles
Wscript.Echo "File in root folder:" & objfile.Name
Next

Yes, that describes the problem, but not the solution - short of changing the names of the folders. There is another solution.  That is, to map a logical drive to the folder so that the path to subfolders and files is shortened.  Here is a procedure that offers a scripted approach that I use to map folders with long names to a drive letter and then opens a console window at that location ...
Dim sDrive, sSharePath, sShareName, aTemp, cLtr, errnum
Const sCmd = "%comspec% /k color f0 & title "
Const bForce = True
if wsh.arguments.count > 0 then
  sSharePath = wsh.arguments(0)
  aTemp = Split(sSharePath, "\")
  sShareName = aTemp(UBound(aTemp))
  cLtr = "K"
  with CreateObject("Scripting.FileSystemObject")
    Do While .DriveExists(cLtr) and UCase(cLtr) <= "Z"
      cLtr = Chr(ASC(cLtr) + 1)
    Loop
  end with
  sDrive = cLtr & ":"
Else
  sDrive = "K:"
  sSharePath = "C:\Documents and Settings\tlavedas\My Documents\Script\Testing"
  sShareName = "Testing"
end if
with CreateObject("Wscript.Network")
  errnum = MakeShare(sSharePath, sShareName)
  if errnum = 0 or errnum = 22 then
    .MapNetworkDrive sDrive, "\\" & .ComputerName & "\" & sShareName
    CreateObject("Wscript.Shell").Run sCmd & sDrive & sShareName & "& " & sDrive, 1, True
    .RemoveNetworkDrive sDrive, bForce
    if not errnum = 22 then RemoveShare(sShareName)
  else
    wsh.echo "Failed"
  end if
end with
function MakeShare(sSharePath, sShareName)
Const FILE_SHARE = 0
Const MAX_CONNECT = 1
  with GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    with .Get("Win32_Share")
      MakeShare = .Create(sSharePath, sShareName, FILE_SHARE, MAX_CONNECT, sShareName)
    end with
  end with
end function
sub RemoveShare(sShareName)
Dim cShares, oShare
  with GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set cShares = .ExecQuery _
      ("Select * from Win32_Share Where Name = '" & sShareName & "'")
    For Each oShare in cShares
      oShare.Delete
    Next
  end with
end sub
The SHARE that must be created for this to work is marked as having only one connect (the calling procedure).  The mapping and share is automatically removed when the console window is closed.  In the case cited in this posting, this approach could be applied using the subroutines provided so that the user's script creates the share/mapping, performs its file operations and then removes the mapping/share.  Ultimately, it might be more useful to change the folder structure, as suggested in the KB article, since working with the created folders and files will still be problematic - unless the drive mapping is in place.Tom Lavedas

Similar Messages

  • 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

  • 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.

  • 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.

  • How to get uploaded file name and path in BefExportToDat event script

    I would like to get hold of the uploaded file name and full path in the event script "BefExportToDat", as I need to extract values from particular fields. However I have not yet found a way to do this.
    - The input variable "strFile" returns the .Dat file path in the Outbox, to which it is about to export the data. This is no use to me.
    - The API variable RES.PstrFilename is returning nothing
    I am using RES.PstrFilename in the "BefFileImport" event script in a different FDM application and it works fine, however I need to find a way to get this to work in the "BefExportToDat" event script.
    Please let me know how this might be achieved.

    I am looking through the API calls in FDM Workbench, but cannot see the table (tPOVPartitions) you mentioned listed. Is this the correct name? And do I just use the function listed in the object browser to run the query?
    Furthermore (going back to my initial thoughts of using strFile), it appears that although the variable contains the .Dat filename and path, the actual file is non-existent when "BefExportToDat" is executed:
    Error:
    Error: Export failed.
    Detail: File not found.
    This would make sense, but it does make the variable "strFile" a little pointless since one cannot make use of the file in this particular event script. Do you please have any thoughts on this?

  • 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.

  • How to print the report file name and path and the last mod date

    Good morning,
    I am trying to print on the footer of the report the report file name and path as well as the report last modification date.
    Anyone would know how I can do that? I have checked the doc but found nothing.
    Thks. Philippe.

    Did you ever determine how to print report name and report last mod date?
    Thanks

  • How to find PG.xml file name and path associated with a FUNCTION

    Hi,
    I am having a function:IRC_VIS_HOME_PAGE with Web HTML value as below:
    OA.jsp?akRegionCode=IRC_VIS_HOME_PAGE&akRegionApplicationId=800&OAPB=IRC_BRAND
    How to find PG.xml file name and path assoicated with above funtion.
    Thanks,
    ashok

    Ashok,
    Function IRC_VIS_HOME_PAGE will have 2 parameter defined for it which are OASF and OAHP where
    OASF=<SelectedFunctionName> - this tells the Framework to select this function in the given "Home Page" menu context.
    OAHP=<HomePageMenuName> - this is used ONLY with the OASF parameter, and it is used to establish the current menu context. It should point to a "Home Page" menu.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How do I put the file name and path into either the header or the footer?

    I need to keep track of pdf documents as their names or locations sometimes change.  I need to show both file name and path, preferably in the header.  I would also like it to refresh automatically when I change, say, the file name, but that's not as essential as the basic function of showing the file name and path.

    You will need to do this with a text field and a Javascript that executes on open.

  • File Name and Path special field

    Post Author: puser01
    CA Forum: .NET
    I have a report created in CR 9 with the File Name and Path special field on the report displayed correctly. when i try to run it on CR XI environment i get this:
    C:\WINDOWS\TEMP\{4D86438D-54F5-4EEF-A0AB-05D5EB2BFF35}.rpt
    How can i correct this?

    Our installer names don't make it easy for the new user, or the seasoned veteran for that matter. Although both those installers have 2008 in the name, they are for entirely different products.
    CRRedist2008_x86.msi
    This MSI installer is used to install the runtime for Crystal Reports Basic for Visual Studio 2008 - version 10.5.
    cr2008fp35.exe
    This installer package is used to install the CR .NET runtime for Crystal Reports 2008 - version 12.3.
    Since you've updated your development system to Crystal Reports 2008 you'll only want to use the runtimes listed on this reference page - http://www.sdn.sap.com/irj/sdn/crystal-xcelsius-support?rid=/webcontent/uuid/10e38d93-7f07-2d10-beae-e739182f8ada. [original link is broken]
    I suggest either of these
    SP 3
    https://smpdl.sap-ag.de/~sapidp/012002523100007123592010E/cr2008sp3_redist.zip
    FixPack 3.5
    https://smpdl.sap-ag.de/~sapidp/012002523100006341772011E/cr2008fp35_redist.zip

  • File name and path should be passed as parameter

    hi all,
    i am writing a set of statements into the text file. But i have to pass the file name and also path as a user enterable parameter.
    please suggest me to proceed further.
    for ex: i am storing it as
    output:=text_io.fopen(c:abc\def\out.txt','w');
    right now i am giving like this and storing the data, but now i have to allow file name and path as user parameter.
    please suggest me.
    Thanks..

    Hi,
    for ex: i am storing it as
    output:=text_io.fopen(c:abc\def\out.txt','w');
    right now i am giving like this and storing the data, but now i have to allow file name and path as user parameter.
    please suggest me.Well, how hard can it be?
    You have to get those two parameters from your application into two variables, say "v_filename" and "v_pathname", and then create the file just the same way using the variables to construct the full path :
    output:=text_io.fopen(v_pathname || '\' || v_filename,'w');

  • Log File name and path to check Excel Download

    Hi ,
    When we download a report in Excel/PDF/HTML is it logged in any log file ? What is the log file name and path?
    Regards
    Anand

    Hi...
    one of my user tried to download the report in excel format. that excel was not opening. then he tried to download the same report again. this time he was able to open thee excel.
    So he wants to investigate why this happened first time. could you please suggest how we can investigate this?
    Regards
    Anand

  • Separating file name and path

    Hi,
    I need to separate the file name and path of the file which I am uploading from my BSP appl.I am using SO_SPLIT_FILNAME_PATH ,but it is not working because this fm identifies '\' only from GUI front end.
    How do I separate the file name and path in BSP ?
    Regards,
    Ananya

    Assuming that you are using File Upload tag for file upload:
    DATA: fileUpload TYPE REF TO CL_HTMLB_FILEUPLOAD.
    fileUpload ?= CL_HTMLB_MANAGER=>GET_DATA(
                           request = request
                           id      = 'myUpload'
                           name    = 'fileUpload' ).
    file_name      = fileUpload->file_name.
    file_mime_type = fileUpload->file_content_type.
    file_length    = fileUpload->file_length.
    file_content   = fileUpload->file_content.
    Data : filepath type string,
           filename type string,
           t1 type string.
    filepath = file_name .
    while filepath CA ''.
      split filepath at '' into t1 filename.
    endwhile.
    In my sample code above, filename attribute will contain the name of the file uploaded.
    Hope this solves the problem.
    Regards,
    Ravikiran.

  • Question about pass file name and path to file write adapter

    I need to pass file name and path to file adapter for write. I got partial answers from thread Re: Get File name using File Adapter , but seems InboundHeader_msg or outboundHeader_msg only takes file name, how do I pass file directory?
    since I still have to specify file format (like xxx_%xx%.txt) in the file adapter wizard. Will this name conflict with what the name defined in InboundHeader_msg ?
    Similarly, how can I pass a file name and path to a file synchread adapter?
    Thanks,
    Message was edited by:
    user531689

    Just overwrite the filename in the WSDL file that was generated

  • Target Data File Name and Path

    Hi,
    I'm trying to deploy a mapping that writes data into a file, but I need to dynamically set the name and the directory where I want to write this file. The only workaround I found was manually change the pl/sql generated code and change the values in the FOPEN call with a parameter, but this is no what I really want to do. Does anyone know how to tell WB not to hardcode the file name and path?
    I really appreciate you time,
    thanks in advance,
    Matias

    Carla,
    Unfortunately our releases do not go that fast...
    What you could do as an intermediate solution (this is what I would do) is create your mapping and load into a staging table (this can happen in set-based mode so would be fast). In a post mapping process you manually write to the flat file by making the calls to FOPEN etc. by selecting from the staging table. The post mapping process can have an input parameter that you dynamically pass (i.e. via a mapping parameter) and set the file name.
    Mark.

Maybe you are looking for