There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
DOS/PDA/Other
Tag Cloud
adware audio bios blue screen boot bsod computer connection crash dell email error excel firefox freeze freezing google hard drive hardware hijackthis install internet laptop linux malware network no sound outlook problem reboot recovery redirect router screen server slow sound speakers spyware startup trojan usb video virus vista windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/PDA/Other >
Solved: Batch File - For Loop Counting Characters within XCopy

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
02-Jun-2009, 07:18 PM #16
Quote:
Originally Posted by Squashman View Post
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.

I downloaded and am using the above. It is much better and easier to use than version 1.4 which is what I had.

However, when I convert over to an EXE it crashes. I have pinpointed it to the following line:
rmdir %temp% /S /Q

I have attempted to write this as:
rmdir "%temp%" /S /Q

It makes no difference. It still crashes.
I believe this is because when run the exe files creates temporary exe files in the temporary directory. I saw there is an option to run from the current directory but that made no difference when compiling.

What are some of the other programs you are aware of that may allow that line after converted?

Thanks,
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets, Corporate Gifts
Resources LLC: Water Treatment Coagulation, Water Recycling
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 5,315 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
03-Jun-2009, 05:08 PM #17
Have you tried RmDir /S /Q "%temp%"
Or use a subfolder in %temp%:
Set _tmp=%temp%\ScrFixTmp%Random%
Then RD /S /Q "%_tmp%"

Jerry
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
03-Jun-2009, 10:10 PM #18
Jerry,

The first one still crashes.
The next one returns back
The system cannot find the file specified.

It appears the second one just creates a temporary folder and then removes that folder.

It crashes out with the error:
The system cannot find the path specified.
The system cannot find the file specified.
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets, Corporate Gifts
Resources LLC: Water Treatment Coagulation, Water Recycling

Last edited by scrfix : 03-Jun-2009 11:58 PM.
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
04-Jun-2009, 11:44 AM #19
Jerry, Squashman,

I found something that will work just as good. I did some testing and I can accomplish almost the same task with

Code:
del %temp%\* /F /S /Q
This one doesn't crash the exe.
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
04-Jun-2009, 02:32 PM #20
I spoke too soon. That does not work. However I figured out why it doesn't work.

When a batch file "compiler" compiles yours file, it merely encrypts the shell of the file. It creates files in the temp directory that then get wiped out by deleting them and bam crash.

Wayne
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets, Corporate Gifts
Resources LLC: Water Treatment Coagulation, Water Recycling
Squashman's Avatar
Distinguished Member with 14,920 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
04-Jun-2009, 03:09 PM #21
Don't use Environmental Variables that the Operating System already uses as your variable names!
Squashman's Avatar
Distinguished Member with 14,920 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
04-Jun-2009, 03:18 PM #22
I compiled this and it worked just fine.
Code:
set _tmp1=E:\test1
rmdir /S /Q "%_tmp1%"
pause
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
04-Jun-2009, 03:40 PM #23
Boy, I don't know what programming they have in these forums but whever I do a copy and a paste for some code to this quick reply it locks up Internet Explorer tighter than a drum and I end up having to close out and lose everything I typed.

Now, if I copy and paste it to notepad and then from notepad to here it is just fine.

The reason yours works is because you are creating a temp directory and then removing that directory.

What these so called compilers do is to encrypt the shell of the file. When you run the program, it creates a <random-name-here>.tmp that hosts your renamed <random-name-here>.bat file (unencrypted for the world to see)

There are no options to tell it to mark the bat file as hidden or to tell it where to save it. It automatically saves it in the %temp% directory.

I was using the actual system variable %temp% not a variable of my own.

So when you click on that exe to execute your command, it creates a file in the %temp% directory (other compilers do it differently but basically the same). This will be either a hidden temp folder, a temp folder.tmp or the actual bat file all renamed to a random name. It then executes the bat file to run.

Because I am cleaning out the %temp% folder within my bat file before executing my other commands, it then removes the bat file being used to run the program therefore the ending result; crash.

For a test either create the temp folder, store your bat file in the temp folder, then run the rmdir /S /Q on the temp directory and you will see the same effect.
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets, Corporate Gifts
Resources LLC: Water Treatment Coagulation, Water Recycling
Squashman's Avatar
Distinguished Member with 14,920 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
04-Jun-2009, 03:56 PM #24
Would be helpful from now on if you could really explain what you are trying to do instead of us guessing all the time. I had to assume you were using an Environmental Variable improperly again because you had been warned about that before.
Squashman's Avatar
Distinguished Member with 14,920 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
04-Jun-2009, 04:04 PM #25
I can't replicate your problem. I ran my batch file and then looked in the directory of the temp variable and there is nothing with a time stamp or even close to a time when the batch file started. And I still have the batch file running.
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
04-Jun-2009, 04:16 PM #26
Not a problem. I will try to make things clearer however being warned about it before would signify that I now know not to do that.

If the following code was compiled and ran the issue would have been repeated.

Code:
rmdir %temp% /S /Q
pause
There is no sense in inputting 600 lines of code into here when all I am speaking about is 1 line that if ran can be repeated very easily.

I just read your above statement about not being able to repeat the error. Compile and run the following code from the exe file:

Code:
@echo off 
rmdir %temp% /S /Q 
echo succesfully removed temp directory
@pause
It will start and error out with:
The system could not find the specified path.
The system could not find the specified file.
The window will then disappear instead of going to a pause screen.

Now compile and run the following code with the exe file:
Code:
@echo off 
del %temp%\* /F /S /Q
echo succesfully removed temp directory
@pause
It will start to run and then the following error will come up:
Deleted File - pathway\name of bat file.bat
The window will then close without reaching the pause

This is because the compiler as I explained above creates an executable shell around the bat file and then when executed it stores the real unencrypted bat file in the system %temp% directory. So when you are cleaning up the junk files on the computer and you are cleaning the %temp% directory, it removes the files those compilers create. I have attempted 4 different compilers attempting to work like this and they all do the same thing in various formats.

The only way I was able to catch the errors was by precisely timing a print screen. I am sure there are other ways however I captured the errors nevertheless.

I have only tested this on a Vista system.
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets, Corporate Gifts
Resources LLC: Water Treatment Coagulation, Water Recycling

Last edited by scrfix : 04-Jun-2009 04:24 PM.
Squashman's Avatar
Distinguished Member with 14,920 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
04-Jun-2009, 04:33 PM #27
I changed my original batch file to the %temp% variable and it deleted everything except for files and directories in use by programs that are already running. I am running XP.
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
04-Jun-2009, 04:37 PM #28
If you compile exactly what I posted above, you should get the same errors as described.

If you are running it from a batch, it works just fine.
You have to run it from the exe to repeat the error.
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
04-Jun-2009, 05:14 PM #29
I can always exclude the %temp% directory from being copied altogether with /XD %temp% with robocopy or /EXCLUDE:%temp% in xcopy and then just clean the temp directory at the end of the batch. It is an ugly work-a-round but it will work. Of course this is all theory right now and has not been tested.

Unless anyone has anything better?
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets, Corporate Gifts
Resources LLC: Water Treatment Coagulation, Water Recycling
Squashman's Avatar
Distinguished Member with 14,920 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
04-Jun-2009, 06:37 PM #30
Quote:
Originally Posted by scrfix View Post
If you compile exactly what I posted above, you should get the same errors as described.

If you are running it from a batch, it works just fine.
You have to run it from the exe to repeat the error.
That is basically what I did and I didn't get any errors.
This is what was in my batch file that I compiled.
Code:
rmdir /S /Q %temp%
Must be a vista issue.
Closed Thread Bookmark and Share

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.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 01:08 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.