 | Senior Member with 249 posts. | | Join Date: May 2009 Experience: Computer Repair Expert | | Solved: Batch File - For Loop Counting Characters within XCopy 1st Object:
Count the number of characters in a pathway for XCopy.
I have figured a way out to do this. It is the execution I need help with. Mine keeps crashing on me. 2nd Object:
This is just an if/else statement so it shouldn't be hard. If I have issues after this resolution I will bring it up. Notes:
The below code is just a snippet from my code and I have removed most Variables to make things easier to read. This program just hangs. I know the counting works by itself. I know the xcopy works by iteself. What am I doing wrong? Code: @echo off
set MyVar=xcopy /L /Y C:\Windows G:\Windows
for /f %%a in ('%MyVar%') do (
set #=%MyVar%
set length=0
:loop
if defined # (set #=%#:~1%&set /A length += 1&goto loop)
echo %MyVar% is %length% characters long!
)
Thank You for any insight and help.
Wayne | | Distinguished Member with 5,315 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate | | Hi Wayne.
A few things
Best to comment out the echo off statements so you can see what it is doing. That can help you find things.
What I do is use this:
@Echo %dgb%Off
To turn off echo I just type set dbg=1, to turn it on type Set dbg=0 (I actually have two batch files with the appropriate set statement, and just type dbon and dboff)
1:
for /f %%a in ('%MyVar%') do (
You have not specified the delimiters, so the default of space and tab will be used. Any paths/filenames with spaces will be truncated at the first space. So use this:
for /f "delims=" %%a in ('%MyVar%') do (
2:
set #=%MyVar% echo %MyVar% is %length% characters long!
You are setting # equal to the Xcopy command. This should be the loop variable. Same with the Echo statement:
Set #=%%a echo %%a is %length% characters long!
2:
set #=%#:~1%
If inside a loop you must use delayed expansion. When %#:~1% is expanded, # is actually undefined so this line becomes set #=~1
The ~ vanishes because it's not escaped, so you''ll get these three lines for the output: Code: C:\test1>if defined # (set #=1 & set /A length += 1 & goto loop )
C:\test1>if defined # (set #= & set /A length += 1 & goto loop )
C:\test1>if defined # (set #=~1 & set /A length += 1 & goto loop )
Length will actually get set to three as the goto statement actually ends the For loop, so delayed expansion is not needed after the first one, but by then the damage is done.
3:
You can't use goto inside a For statement. The goto ends the For loop, even if you goto a label inside the for loop. So you need to call a routine to get the length.
Once the For loop is ended by goto, you don't need delayed expansion, so the # variable will be processed, but the 1st time through sets it to 1. Not quite sure why it isn't seen as undefined after the 2nd line though
4:
If G:\Windows doesn't exist, it will hang as Xcopy is asking if G:\Windows is a file or directory and waits for your response. This question is never output to the screen though, it's output to the loop variable. Just need to specify the /I switch on the Xcopy command.
Give this a try. It uses a more efficient length routine, it checks blocks of 9 characters instead of every character so is a bit faster. Code: @Echo %dbg%Off
SetLocal EnableDelayedExpansion
Set MyVar=xcopy /L /I /Y C:\Windows G:\Windows
For /F "delims=" %%a In ('%MyVar%') Do (
Call :_GetLength "%%a" _Length
Echo %%a is !_Length! characters long!
)
Goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Subroutines
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:_GetLength
:: Gets the length of a passed variable
:: Arguments : "string" rvar
:: Returns : Length of string in specified return var
:: Usage
:: Call :_GetLength "%str%" rvar
:: "%str%" : String to find length of. Must be quoted if contains spaces
:: rvar : Name of variable to be used to return the length
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SetLocal
Set _Len=0
Set _Str=%~1
If NOT Defined _Str Goto :EOF
Set _Str=%_Str:"=.%987654321
:_Loop
If NOT "%_Str:~18%"=="" Set _Str=%_Str:~9%& Set /A _Len+=9& Goto _Loop
Set _Num=%_Str:~9,1%
Set /A _Len=_Len+_Num
EndLocal&Set %2=%_Len%&Goto :EOF
HTH
Jerry
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations?
Last edited by TheOutcaste : 17-May-2009 10:55 PM.
Reason: Hit Send too soon, forgot some quotes and stuff
| | Distinguished Member with 5,315 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate | | Sorry about that, didn't realize I'd hit send. Also wanted to add that if you have a path longer than 250 or so, xcopy may give an error will quit since the /C switch isn't specified. And the length of the long path won't be calculated.
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations? | | Senior Member with 249 posts. | | Join Date: May 2009 Experience: Computer Repair Expert | | Jerry,
Thank you for that explanation. That tells me exactly where I went wrong. It also explains to me why these two items work perfectly separate but I could not get them to work together.
Now, if I remember from my last quesiton, the :eof is an internal function necessary to break out of for loops or was that just eof with the :?
Thank you for the tip on the /C. This whole test is for exactly that.
Let me ask you this. If I have a pathway that is 300 characters long. (Just ran into this and it errored out, of course.) The file was some HP random file located in the drivers directory in system32 something like HP_ASDFTRRADFFGASDWFSTGSDR... etc etc etc etc and it had special characters in it as well. What I am attempting to do is to count that file or pathway to the file. If that file or pathway to the file reaches 241 or More (I forget off the top of my head how to write equal to or greater than in batch) characters, skip the file, write to a log file stating that the specific pathway and the actual fille were not able to be copied and if it is 240 or LSS characters go ahead and copy it.
With the /C the file that I am talking about will it do that or will it error out.
Here is what I am running into. Let's take that example from above:
1. The xcopy starts to copy it hits that file and stops copying that line of code and goes to the next line in the batch. This is bad because it stops copying altogether. Let's say that line in the batch is (xcopy /C C:/Windows G:/Windows) [I have left out all other switches just for example sake]. This means I have have of the drivers directory saved and the other half does not get copied.
Here is what I need:
1. I need for it to just skip that one file and continue copying that line in the batch file.
I could probably do this:
1. I could store a portion of the name (The first 20 characters should be enough) name of each and every file being copied into a variable (%namestore%) and if Error Level 1 (I think is the error that is returned) occurs while copying then (set filename=%namestore%) and let it error out however restart the copying loop from the beginning and add exclude:%filename% that xcopy. I use a time stamp to copy so it will not start copying from the beginning of every file again. This way when it restarts, it will start back at any files that have not been copied. When it gets to the super log file that it cannot copy it skips it. Now the issue with that is that is great for those super long file names as mentioned above however it does nothing for those people that save their documents within folders within folders within folders withing folders and utilize names such as "My super really extra long no reason for it being this long except that I want to look cool folder name". When they have 10 of those stored within each other then there is a problem or would there be. With the described above, it should still store the name into the variable and then write to the log file. I could then create a batch, put it in the start up of the computer to warn them that they had errors and then auto delete that batch once they push any key on their keyboard.
One item at a time I guess.
Does it sound like we have to go that far or is there another way of performing what I want to perform.
I just want to skip the line item that is being copied if it is over 240 characters and continue copying the rest of the files.
Thanks,
Wayne Computer Repair Gift Baskets Modular Gold Plants
Last edited by scrfix : 18-May-2009 11:02 AM.
| | Distinguished Member with 14,920 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! | | Quote:
Originally Posted by scrfix Jerry,
Now, if I remember from my last quesiton, the :eof is an internal function necessary to break out of for loops or was that just eof with the :? | Use GOTO :EOF will basically go the end of a batch file or end a subroutine. So if you called a subroutine and want to end it you can goto :eof. If you want to terminate your batch file you can use goto :eof.
CMD processor understands the label :EOF as being the end of a process and terminates it. | | Distinguished Member with 14,920 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! | | | | | Senior Member with 249 posts. | | Join Date: May 2009 Experience: Computer Repair Expert | | Squashman,
Thanks for those pages. I believe the second one is exactly what I am looking for but I am having a hell of a time trying to read this thing. Code: @echo off
:: Calculates the string length of the first parameter.
:: PARAM
:: 1 String to return length of
:: RESULT Integer length of tring
:STRLEN
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET I=-1
SET T=%~1
:STRLEN_LOOP
SET /A I += 1
IF NOT "!T!" == "" IF NOT "!T!" == "!T:~0,%I%!" (
GOTO :STRLEN_LOOP
)
ENDLOCAL & SET RESULT=%I%
GOTO :EOF
@pause
Note:
I added the @echo off and the @pause to the code.
Breaking this down:
:STRLEN - Label for STRLEN (No problem)
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION - (I understand how to read this. Just not sure what it does or why it is important.)
SET I=-1 - Set the variable I to negative one?
SET T=%~1 - Set the variable T to (I have no idea)
:STRLEN_LOOP - Label for STRLEN_LOOP (No problem)
SET /A I += 1 - Set the variable I to be an expression and += (no clue) to 1
IF NOT "!T!" == "" IF NOT "!T!" == "!T:~0,%I%!" ( - I have no clue what this line says. I do not know why there are 2 IF NOT "!T!" nor do I understand why there is two !'s on either side of the T.
GOTO :STRLEN_LOOP - After Verification go back to STRLEN_LOOP and start over again. (No problem)
)
ENDLOCAL & SET RESULT=%I% - I am unsure why we are setting the result to = to %I%.
GOTO :EOF - Leave the batch file
I am also unsure as to where they are getting string length or how to incorporate string length into this.
Any help would be wonderful. I believe from reading this that this is exactly what I am looking for. It looks at every character and counts it individually until finished. If I can put an IF statement within the loop to say If the characters go over 240, skip this file and write to a log file and if not go ahead and copy that file, this resolves this issue. I just have to learn how to read this and how to incorporate a string into it.
Wayne | | Distinguished Member with 5,315 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate | | I see Squashman beat me to it while I've been playing with long path names, but here's my take on the :EOF
:EOF is a predefined label that is always at the end of the file.
So this exits the current script, same as using Exit /B
If you are familiar with BASIC, Goto :EOF is equivalent to RETURN
The /C switch will continue on copy errors like Access Denied, Sharing Violations (file in use), or File not found (deleted/moved/renamed before xcopy got to it).
It will not continue when it hits a long path. You get an Insufficient memory error and Xcopy quits. So you can't use it to find long paths.
Easiest solution is to use Robocopy as I mentioned in post 9 in the previous thread, which doesn't have that path length limitation. It's included with Vista, and can be downloaded for XP/Win2K as part of the Win2K3 Resource Kit. (This Vista version won't work on XP)
The Resource kit is an 11.8 MiB download, but you only need to download it once. If you have multiple PCs, you can have the batch file check to see if robocopy.exe exists on the system, and if not copy it to the Windows\system32 folder from a network share, robocopy.exe is only 78 KiB. Or copy it at the same time as the batch file is copied to the system
If you have to use xcopy, there's a couple of options. All depends on if you have multiple nested folders, or just a couple levels of folders, and a few files with a very long name.
You can use Dir to do a directory list. It will send this error message to STDERR when it finds a long path: The directory name <path listed> is too long.
You can run a DIR command and check for that error message. Dir /B /S "C:\Path\*.*" >Dirlist.txt 2>LongPath.txt
You can then create an exclude file to exclude that path. However, this may not find some long paths.
I created a group of nested folders, then renamed the top level folder to make the path too long. With just the right length, Dir will not give an error, nor will it list all the files/folders. In my test, it will list the 2nd to last folder, but not the files it contains, or the folder. And Xcopy doesn't cause an error, but the files in that 2nd to last folder and it's subfolder are not copied.
Added a couple more characters, and Dir now gives an error, but Xcopy still runs, but again doesn't copy the last two folders.
I then created the longest filename I could in the root of the drive, which is 256 characters (260 counting the C:\ at the front, and the <NULL> at the end)
Created a folder named New Folder, used Robocopy to move the file.
Dir will list the file, and Xcopy gives an error.
Moved it to C:\Test Dir\New Folder, and Dir will list it. Xcopy won't copy, nor does it give an error. Tried copying using the short file name, and xcopy doesn't give an error, but still won't copy the file.
You can't exclude the filename. Even trying a partial match of the first few characters fails, because Xcopy has to read the filename before it can try to match it to what is in the exclude file.
Renaming using the short name also fails with this error:
The system cannot find the path specified.
Then the Command Prompt generates an error and closes. The dump file indicates this: Stack buffer overflow - code c0000409
So, you can check to make sure Xcopy won't fail, but you can't guarantee that you haven't missed some files.
You use Dir to find any long paths, then exclude the path so Xcopy won't cause an error.
You then check the total length of the files Dir finds, and exclude those paths.
Then process the list to create a list of files in the excluded folders that you can copy.
You then individually copy everything in the excluded folders that is not too long, or create a share at the lowest level folder and then repeat all the above starting from that share.
But, if the filename itself is over 256 characters, there is nothing you can do with it with a batch file. I'm not even sure if Dir would be able to list it if it's too long.
You can't create a name longer than 256 characters using the Command Prompt or Explorer, but any program can by using the Windows API, which allows up to 32,767 characters in the path.
Much much easier to just copy Robocopy to each system.
This is what I've got so far. Still need to go through the Will Copy list and remove any files that are in excluded paths and add them to the Excludedlist file, then decide how to copy them. Code: @Echo Off
SetLocal EnableDelayedExpansion
Set _SrcFld=C:\Test Dir
Set _DstFld=D:\Test Dir
PushD %_SrcFld%
Set _TPath=C:\Test1\
If Exist "%Temp%\*.}x{" Del /F "%Temp%\*.}x{"
Dir /B /S /A-D >"%Temp%\Dirlist.}x{" 2>"%Temp%\LongPath.}x{"
For %%I In ("%Temp%\LongPath.}x{") Do If %%~zI==0 Goto _NoLong
For /F "Usebackq Delims=" %%I In ("%Temp%\LongPath.}x{") Do (
Set _Dir=%%I
>>"%Temp%\Exclude.}x{" Echo !_Dir:~19,-13!
)
:_NoLong
:: Now check dirlist for names/paths over 256 characters
For /F "Usebackq Delims=" %%I In ("%Temp%\Dirlist.}x{") Do (
Call :_StrLen "%%I"
If !_Result! LSS 256 (
>>"%Temp%\WillCopy.}x{" Echo %%I
) Else (
>>"%Temp%\Exclude.}x{" Echo %%~dpI
>>"%Temp%\excludedlist.}x{" Echo %%I
)
)
Copy "%Temp%\Exclude.}x{" C:\Exclude.}x{>Nul
Xcopy /CEHIRYL "%_SrcFld%" "%_DstFld%" /Exclude:C:\Exclude.}x{
Del /F C:\Exclude.}x{
:_End
PopD
::If Exist "%Temp%\*.}x{" Del /F "%Temp%\*.}x{"
EndLocal
Goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This routine does a divide by 2 type check.
:: Faster than counting each character for strings longer than 16
:: Returns the string length.
:: PARAM
:: 1 String to get length of
:: RETURN Integer string length in _Result
:_StrLen
SetLocal EnableExtensions EnableDelayedExpansion
Set _Str="%~1"& Set _Str=!_Str:~1,-1!
Set _Len=0
:: Max string length is 8191, see http://support.microsoft.com/kb/830473
Set _Pos=8192
:_StrLenLoop
Set /A _Pos /= 2
If NOT "!_Str!" == "" (
If NOT "!_Str:~%_Pos%,1!" == "" (
Set /A _Len += %_Pos% + 1
:: work on rest, that is after _Pos+1
Set _Str=!_Str:~%_Pos%!
Set _Str=!_Str:~1!
)
Goto :_StrLenLoop
)
EndLocal & Set _Result=%_Len%
Goto :EOF
Jerry
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations? | | Distinguished Member with 5,315 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate | | Actually the first one is more efficient for strings longer than 16 characters. I'm not sure how well either will deal with strings that contain any of these: !%^|<>
Check the help for these commands:
Set /?
SetLocal /?
Call /?
For /?
That covers most of what is in the routine.
Also don't turn off echo. Then you can see what the variables expand as for each line, which might make it clearer.
You would call the routine like this: Call :STRLEN "what is the length of the string inside these quotes"
The quotes are requited, and the length of the characters in blue is stored in the variable RESULT Quote:
Originally Posted by scrfix Breaking this down:
:STRLEN - Label for STRLEN (No problem)
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION - (I understand how to read this. Just not sure what it does or why it is important.)
SET I=-1 - Set the variable I to negative one? | Yes, start at -1 Quote:
Originally Posted by scrfix SET T=%~1 - Set the variable T to (I have no idea) | Sets T equal to the passed parameter, first removing the surrounding quotes Quote:
Originally Posted by scrfix :STRLEN_LOOP - Label for STRLEN_LOOP (No problem)
SET /A I += 1 - Set the variable I to be an expression and += (no clue) to 1 | Increment (+=) by 1. To increment by two use +=2 and so on Quote:
Originally Posted by scrfix IF NOT "!T!" == "" IF NOT "!T!" == "!T:~0,%I%!" ( - I have no clue what this line says. I do not know why there are 2 IF NOT "!T!" nor do I understand why there is two !'s on either side of the T. | The ! are just like the % except it indicates the expansion of the variable is delayed until the line is actually executed. The Command processor first expands all variables then executes the line. If you change a variable inside a loop, the change will not be seen unless you delay the expansion of the variable until right before the line is executed. In this case though, it's needed so you can specify the length of the string you are extracting. %Var:~0,%length%% doesn't work, you have to use !Var:~0,%length%! which requires DelayedExpansion
Might be easier to understand if it's split up a bit. Code: IF NOT "!T!" == "" (
IF NOT "!T!" == "!T:~0,%I%!" (
GOTO :STRLEN_LOOP
)
)
If the string (T) is not null, you then do the 2nd If. It compares the string to a substring of length I. If they are not equal, you loop back and increment I
So if the string is ABC, the 1st time though I is 0, you compare:
"ABC" to "" - not equal, loop, increment, I now 1
"ABC" to "A" - not equal, loop, increment, I now 2
"ABC" to "AB" - not equal, loop, increment, I now 3
"ABC" to "ABC" - equal, don't loop, I is the length. Quote:
Originally Posted by scrfix GOTO :STRLEN_LOOP - After Verification go back to STRLEN_LOOP and start over again. (No problem)
)
ENDLOCAL & SET RESULT=%I% - I am unsure why we are setting the result to = to %I%. | The SetLocal at the beginning means all variables in the routine are local. When the EndLocal is executed, the variables vanish. However, since variables are expanded before the line is actually run the line is really this: ENDLOCAL & Set RESULT=3
The variables are released, then you set result to 3, the length of the string. Quote:
Originally Posted by scrfix GOTO :EOF - Leave the batch file | If it's a separate file, Yes, but if it's called as a subroutine, it simply returns to the statement after the CALL. Quote:
Originally Posted by scrfix I am also unsure as to where they are getting string length or how to incorporate string length into this. | The String length is the I variable that is being incremented, and is returned in the variable Result. Quote:
Originally Posted by scrfix Any help would be wonderful. I believe from reading this that this is exactly what I am looking for. It looks at every character and counts it individually until finished. If I can put an IF statement within the loop to say If the characters go over 240, skip this file and write to a log file and if not go ahead and copy that file, this resolves this issue. I just have to learn how to read this and how to incorporate a string into it.
Wayne | As long as you can get the file path/file name. Sometimes hard to do as I showed in my previous post.
However you get the path string, you would just use this to check it: Code: Call :STRLEN "%pathtocheck%"
If %Result% GTR 240 (
:: Skip this file
) Else (
:: Lenght ok, copy
)
HTH
Jerry
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations? | | Senior Member with 249 posts. | | Join Date: May 2009 Experience: Computer Repair Expert |
19-May-2009, 09:16 AM
#10 | First of all,
Thank you very much for testing all of that and the complete answers.
Second,
Leave it to MS to have a limitation is their software and allow their other software to create items over that limitation. Ahhhhhhhhhhh
If I understand this correctly with XCopy:
1. You cannot grab the path of over 256 characters to be able to put into the count. It will simply error out. Question:
Is there something that I can utilize to grab the pathway all the way to the file that is readily available in XP that is not xcopy and does not have that limitation of 256 Characters? Note:
I agree with you on Robocopy that it would be a lot easier and I am currently looking into how to integrate those into all of the systems and I am in the middle of studying Robocopy for all of the proper switches as well as the bugs within Robocopy. However the script I am writing will be utilized on thousands of machines that I am not always going to be sitting at the helm. On a majority of these XP machines, we are not the IT department for them and the rights to install software have been removed by a group policy from the server. So I am forced to work within the limitations that I am provided. As I understand it, I have to install Robocopy onto the machine. It is not a stand alone program I can utilize from a thumb drive or a CD.
Wayne | | Distinguished Member with 14,920 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! |
19-May-2009, 11:42 AM
#11 | Robocopy just needs to exist some where that the user has access to. If all the users have access to a network drive, then put it there. If you can install it locally then put it there.
You could also compile the batch file and robocopy into a single executable. There is a couple of freeware programs out there that do this. | | Senior Member with 249 posts. | | Join Date: May 2009 Experience: Computer Repair Expert |
19-May-2009, 10:15 PM
#12 | Squashman,
Whoa... hold on... you just opened a new world to me here. I knew that I can the batch into an executable. I have a freeware program that when I convert to exe, the exe crashes. I am not sure if it is:
1. The program I am using to convert.
2. The fact that I am using :: for comment files.
3. Something is not compliant in the code and it is having issues.
You are telling me that I can take Jerry's suggestion of downloading it and combine it into an exe file with the bat file. This I did not know.
This hosts a number of new issues and questions however. The first being that as Jerry mentioned that the Vista version of Robocopy will not run on XP. This means that there are two separate versions of Robocopy. Can I integrate them both into 1 executable? Say I download the XP version of Robocopy and name it xprobocopy.exe and the Vista version of robocopy and rename it to vistarobocopy.exe?
How would that work?
If the bat and both exe's were combined, would that cause any issues or would I be able to in the code distinguish between which version of robocopy to utilize. Would I not need to distinguish, I merely utilize the robocopy and the switches I need for either operating system?
If those can be answered perhaps I can look at that road instead. Otherwise, my question still stands, is there another command that I can utilize in a batch to look at the length of a pathway of a file other than xcopy so we can get around this issue with the 256 character limitation?
Wayne | | Distinguished Member with 14,920 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! |
19-May-2009, 10:29 PM
#13 | That bat2.exe utility I use for some of my scripts combine several batch files and executables files into one executable and they work just fine.
This is the one I use. http://www.f2ko.de/English/b2e/download.php
If you determine the OS version in the batch file you could call a different subroutine to use the appropriate robocopy version. | | Senior Member with 249 posts. | | Join Date: May 2009 Experience: Computer Repair Expert |
19-May-2009, 10:58 PM
#14 | I have Bat To Exe Converter 1.4. I am attempting to download yours now.
So if I understand this correctly, it will matter what exe's are combined.
Now, out of curiousity to see if we can answer this. I was looking up other functions within XP.
I found
Copy & Move.
Do either one of those commands have the 256 character limitation that XCopy has?
I also answered a couple of my other questions not related to this by finding a source for bat file commands. What a great website. http://www.ss64.com/nt/
This website just taught me a ton.
I am going to attempt to download the exe files and combine my bat and both robocopy's into 1 exe. If I can do that and still get this to work then I can have 1 file that I run everything from. This would be great.
Wayne | | Distinguished Member with 5,315 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate |
20-May-2009, 12:01 AM
#15 | Quote:
Originally Posted by scrfix Leave it to MS to have a limitation is their software and allow their other software to create items over that limitation. Ahhhhhhhhhhh | All part of progress I guess. In this case, instead of re-working Xcopy, they came up with Robocopy. Doesn't explain why they haven't done something with Explorer.exe to allow the longer paths though. Quote:
Originally Posted by scrfix If I understand this correctly with XCopy:
1. You cannot grab the path of over 256 characters to be able to put into the count. It will simply error out. | Or in some cases it seems it just pretends it doesn't see it at all Quote:
Originally Posted by scrfix Question:
Is there something that I can utilize to grab the pathway all the way to the file that is readily available in XP that is not xcopy and does not have that limitation of 256 Characters? | Dir will find and list some, and will give an error on others. With my test folders I've gotten Dir to list a total path of 511 characters, using a file with a 256 character name. And it will list a path of 270 characters. Might go a few more, it lists that folder, then the following line, which would list the contenets, says the path is too long. I suspect it means that something IN that folder is too long and it can't actually display what it is complaining about. Haven't done enough testing to pin down the exact length.
Done a little testing with VB Script, it doesn't list as much as the DIR command does. I think that you can directly access the Win32 APIs though, so there might be a way using VB Script. It can be done using .Net. Haven't done much testing with WMIC yet either, but I suspect it would also have to access the APIs to deal with long paths.
I've also tried using \\?\ which denotes using unicode, but it doesn't make a difference. (These might be an interesting read: Long Paths in .NET, Part 1 of 3 and File Names, Paths, and Namespaces)
I'm currently at the point where Dir lists 94 files (when I have 100 files), but Xcopy only lists 79. Xcopy doesn't give an error though. Do Dir will find some that Xcopy will miss, but doesn't get them all.
And I haven't figured out how to create a file with a name longer then 256 to test with yet Quote:
Originally Posted by scrfix Note:
I agree with you on Robocopy that it would be a lot easier and I am currently looking into how to integrate those into all of the systems and I am in the middle of studying Robocopy for all of the proper switches as well as the bugs within Robocopy. However the script I am writing will be utilized on thousands of machines that I am not always going to be sitting at the helm. On a majority of these XP machines, we are not the IT department for them and the rights to install software have been removed by a group policy from the server. So I am forced to work within the limitations that I am provided. As I understand it, I have to install Robocopy onto the machine. It is not a stand alone program I can utilize from a thumb drive or a CD.
Wayne | That can be a hassle, but as Squashman has already said, Robocopy actually is a standalone app. If this script will run from a CD/Thumbdrive, you can just include it on the CD/Thumbdrive. Then use %~dp0Robocopy.exe from the bath file to run it. ( %0 is the batch file name, and the ~dp modifiers give just the drive and path).
If the script is something they will be installing then I'd have to second this: Quote:
Originally Posted by Squashman You could also compile the batch file and robocopy into a single executable. There is a couple of freeware programs out there that do this. | I've not done this myself, but Squashman can certainly guide you here.
You could include both the XP and Vista versions of Robocopy (with different names) then have your script check the OS and use the version that is appropriate. The Vista version is 109KiB, XP is 78 KiB.
Odd though, the Win7 Beta Robocopy claims its the same version as Vista (XP 027, 5.1.10.1 027) but is only 92.5 KiB).
And here's a few more links:
DOS and VB Scripting Links Command-line reference A-Z Using batch parameters Windows 95/98/ME Batch file Tutorial (Still a good basic reference for WinNT/2K/XP) Batch File Functions for NT4/2000/XP/2003 Rob van der Woude's Scripting Pages Microsoft Script Center Beginners Guides: WindowsXP Command Prompt Beginners Guides: Understanding and Creating Batch Files
Jerry
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations? |  THIS THREAD HAS EXPIRED.
Are you having the same problem?
We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.
| | |
Smart Search
| Find your solution! | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |  WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
| You Are Using: |
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 08:55 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd. | |
|