Help - Search - Members - Calendar
Full Version: My Actual Letter To A Batch File Expert
MSFN Forums > Customizing Windows and Graphics > Windows Tips 'n' Tweaks

   
Google Internet Forums Unattended CD/DVD Guide
Bold_Fortune
I'm going to try to ask for help this way. I have written this letter to a fellow who has what seems like an excellant batch file tutitorial page. I really do not expect a response from him, but sometimes I can explain myself better in a letter than on a post. Maybe someone here can understand what it is I put in my letter and help me out.


Dear Rob,

I am running Windows XP Home Edition.

Learning batch files is very difficult for me. I need one batch file only. One that will, backup first, and then delete an entire directory...and all it's contents...including what files it contains and any and all subfolders and all their contents.

I would to use it as a master copy with which I might then interchange directories
I want completely backed up and deleted.

I would ask that you please give me an example of how to do this using this directory as the example, that I may keep it and use as that master copy:

C:\Program Files\Common Files\MSSoap

I really do need it laid out for me in an example...because I'm just not "getting it" when someone tries to explain it to me...and they just aren't getting it when I tell them that I really do need it laid out for me in an example.

For example, I got this off a batch file someone made. It backups up and deletes a given file from a given directory.

-------------------------------------------------------------------------------------
Make a New Text Document in system32. Name it New.txt. Now copy this to Notepad and save it to your Desktop as System32.bat or something.
cd C:\
md system32backup
cd c:\windows\system32\
copy c:\windows\system32\New.txt c:\system32backup\
cd c:\windows\system32\
Del New.txt
Now go look on C Root for a folder named "system32backup" with a backedup New.txt file inside.
-------------------------------------------------------------------------------------

If you do not fully understand my request, maybe my showing why I want this batch file will help. On this thread, on the MSFN tweaking site, look for my posts...those by Bold_Fortune. The thread is all about deleting files from XP. I put two years work into the list of files you will first see on that thread.

http://www.MSFN.org/board/index.php?showtopic=11833

I've been trying to get across to forum members there what it is I want exactly, but the things they are telling me, I just don't get. Maybe it's me, or maybe it's the way they are explaining it to someone like me without even the basic knowledge of a batch file.

Thank you very much, Rob. I am looking forward to your reply.

Tony Cataldo (Bold_Fortune)
IcemanND
the folder/file tree you want to delete, is it always the same or changing as the need arises?

Same question as to where to back up? Otherwise where are you backing up to?
Bold_Fortune
IcemanND, I'm not sure I understand "the folder/file tree you want to delete, is it always the same or changing as the need arises?"

The folders I want deleted are always in the same place. Is that what you mean?

I want to back them up on C:\

I want to be able to interchange folders in the batch file...like say today I want to backup and delete

C:\Program Files\Common Files\MSSoap

And tomorrow I will want to backup and delete

C:\Program Files\Common Files\SpeechEngines
un4given1
Bold Fortune: I actually have a batch file "HOW TO" on my site. You can check it out here... http://www.anythingit.org/forums/index.php?showtopic=18
Bold_Fortune
Thanks, un4given1, that stuff is just way over my head. I appreciate it, though. I really was hoping someone would know how to do what I wanted, and then lay it out for me. They either don't know how, or they don't like me already, and won't tell me how..LOL
IcemanND
Here's what I came up with along with an expanation of what each line does.
I'll try to make it as beginner as possible, if you need further explanation let me know.

backup_del.cmd
CODE
@echo off
echo Backing up folder and files...
xcopy %1\*.* %2\ /s /e /c /q /h
echo finished backup.
echo beginning removal of original...
rd %1 /s /q
echo removal complete


Usage: run from a command prompt:
backup_del backupfolder destination
backupfolder - path to folder to backup then delete
destination - path to folder to copy backup files to will be created if it does not exist

Explanation:
@ - prevents single line from being displayed
Echo off - prevents displaying commands when .cmd or .bat is running
echo - displays text listed after echo
xcopy - copies folder tree with appropriate switches
%1\*.* - tells command to copy all files from backupfolder location
%2\ - tells command folder to copy to destination (creates folder if it does not exist)
%0 - refers to command - backup_del in this case
%1 - %9 refer to the commandline switches after the command
/s - copy subfolders containing files
/e - copy subfolders even if empty
/c - Continues copying even if errors occur.
/q - quiet - does not display files/folders as they are copied
/h - copy hidden and system files/folders
rd - remove directory
%1 - folder to remove
/s - removes subfolders and files
/q - quiet - displays no output

Additional related info:
Any program you can run from the command prompt can be run from a .cmd script. There may be a few exceptions, but not many.
If your commandline switches contain spaces they need to be contained within quotes.
Bold_Fortune
Thanks, IcemanND. I'm just a lost cause on this. Now you're talking command prompt, which is something I've never gotten into. I wanted a simple batch file like this one. This one happens to backup and delete any given files...but I wanted it for backing up and deleting a folder. But some simple guideline like this I could use.

cd C:\
md system32backup
cd c:\windows\system32\
copy c:\windows\system32\New.txt c:\system32backup\
cd c:\windows\system32\
Del New.txt

See, if it was as simple as this one above, maybe then all I would have to do is replace c:\windows\system32\ ...with... C:\Program Files\Common Files\MSSoap ...or any other folder and contents I wanted to backup and delete.

Something like this...although, this one doesn't work.

cd c:\
md backup
cd C:\Program Files\Common Files\MSSoap
copy *.* c:\backup
cd C:\Program Files\Common Files\
del MSSoap


I'm not going to get the instructions you gave me. I'm sorry for wasting your time. And thank you very much for taking that time.
XtremeMaC
man u're not trying
batches are not really that hard
every command file on xp has a help file to it.
create a folder and put some stuff in it and try the commands.
u spend your time on finding the unneccessary files in windows, spare some of it on learning bits of dos batch commands

u're better of learning them by yourself
this way u get to play with them
un4given1
My HOW TO breaks it down into the lamest terms possible. I don't know how to help you any more than that, or how XtremeMaC broke it down for you.
Bold_Fortune
Okay, let's forget about this. I wanted a batch file. I really didn't want to study codes and such.

"u spend your time on finding the unneccessary files in windows, spare some of it on learning bits of dos batch commands"

I can't believe you said that. LOL.
un4given1
Iceman broke it down for you... Can't really be broken down more than that.
Bold_Fortune
LOL. Can we just erase this whole thread? I really don't get it, guys, and I'm starting to get a little embarrassed about it. I appreciate all your help. I just don't get it. I must be really lame not to get the lamest terms. LOL.
XtremeMaC
I didn't want to be rude
but I'm just saying I think its better to learn bits of it.

say u need to write another batch file a week from now.
and you desperatly want it to be written right away so you can go on and do some operations on them. you post it on a forum. you wait several hours. nothing. ppl try but its not exactly what you want.

you spend some time on it. read some stuff, search the internet a bit.
learn the roots of it. try them on a test machine. delete recover, copy, change attributes, find words in a file.

its just that I couldn't really understand you. You've said u spent 2 years on finding the files.
I don't think u're dumb. I just think u're not trying, you seem like you don't wanna learn about dos commands. I must say they look very cool on the movies where they hack a computer by typing two works tongue.gif

don't be mad at me pls. I'm just trying to help u, I just believe that u can do it with a minimum effort you put in it.

lets repharase your problem
you want to backup a particular folder to the root of c and you want that folder to get deleted right?

I'll try to write a simple program for you...wait....
devil270975
try this:

CODE
@echo off
set /p SOURCE=Please enter the full path to the files you want to backup:
:: example "C:\Program Files\Common Files\MSSoap"( if you r path contains any spaces remember to use quotes "around the path")
echo.
set /p DESTINATION=Please enter the path for the backup folder:
:: example "C:\Backup"
echo.
if not exist %DESTINATION% mkdir %DESTINATION%
echo Copying files from source folder %SOURCE% to backup folder %DESTINATION%
xcopy %SOURCE%\*.* %DESTINATION% /h /s /e /i /q /y >> %DESTINATION%\BackUp.log
rmdir /s /q %SOURCE%
exit


what this code does is to prompt you for a path for the source files(you only have to enter the path to the files the program will copy everything in the folder) and then again for the destination folder
copy this code to notepad and save as Backup.bat( make sure you enable all file types in the save as dialog box) and run it from anywhere
IcemanND
no.gif The only way to enter the backupfolder destination is at the command prompt. click start, click run, type in cmd, click ok. brings up a dos window (command in non NT os's).

to modify the script I gave you just replace %1 with the directory you want backed up and %2 with the destination it gets backed up to.
so to backup C:\Program Files\Common Files\MSSoap to c:\backup and include all sub folders the script would look like this.

CODE
@echo off
echo Backing up folder and files...
xcopy C:\Program Files\Common Files\MSSoap\*.* c:\backup\ /s /e /c /q /h
echo finished backup.
echo beginning removal of original...
rd C:\Program Files\Common Files\MSSoap /s /q
echo removal complete
XtremeMaC
@devil270975 okay exactly what I was going to do smile.gif
u're addicted to MSFN, u're typing replies at 5am in the morning tongue.gif
Bold_Fortune
QUOTE (XtremeMaC @ Dec 12 2003, 10:47 PM)
don't be mad at me pls. I'm just trying to help u,  I just believe that u can do it with a minimum effort you put in it.

I'm not mad at you at all, buddy. I realize you and others are trying very hard for me...and I do appreciate it.

Let me put it this way, and see if it makes sense. It's not lack of trying...well, maybe it is...but you have to admit that there are many things that you guys don't want to learn either.

It doesn't mean I'm lazy. You guys aren't interested in which files you can delete from your system. I don't think you're lazy for not being interested in that. If you ever ask me about a certain file you happen to be wondering about if you can delete, I'll tell you. I won't make you read my whole thread on deleteing files. LOL.

Once in a great while I will ask someone about a batch file. Like with, Tony Klein, who is most definately one of my true computing heros, I asked him to make up a batch for me that would delete one of those "undeleteable" files from my Temporary Internet Files. He just wrote back:

Paste the following into a blank text document:

cd %UserProfile%
rd /s/q "Local Settings"\"Temporary Internet Files"

Save for example in C: as Clean.cmd.

He didn't ask me to study up on it. LOL. (I'm issuing a lot of "LOL" because I want you guys to know I'm in good humor about all this.)

You guys are great. I really appreciiate all your efforts. But I'm really really getting embarrassed here.
IcemanND
Bold_fortune - here in lies the problem:

QUOTE
Learning batch files is very difficult for me. .....

I would ask that you please give me an example of how to do this using this directory as the example, that I may keep it and use as that master copy: .......
I really do need it laid out for me in an example...because I'm just not "getting it" when someone tries to explain it to me...and they just aren't getting it when I tell them that I really do need it laid out for me in an example.



this makes it sound like you want to learn how to do it so you want examples/explanations. If you just want a batch/script file, just say so. I don't think anyone really has a problem with that. It just seemed like you wanted more than that.
devil270975
@XtremeMAC: i only got in from work a couple of hours ago, and i need my fix...lol...besides the wife is hogging the whole bloody bed, and i dont want to wake her(she not a nice lady when woken up(dont tell her i said that SSSHHHHHHH)...lol...
Bold_Fortune
I've never learned how to use the command prompt, IcemanND. When my command prompt comes up it reads:

C:\Documents and Settings\username\Desktop>

Then what do I do?
XtremeMaC
if u're talking about what to do with this
CODE
@echo off
echo Backing up folder and files...
xcopy C:\Program Files\Common Files\MSSoap\*.* c:\backup\ /s /e /c /q /h
echo finished backup.
echo beginning removal of original...
rd C:\Program Files\Common Files\MSSoap /s /q
echo removal complete

you could just save it in a batch file say copyndelete.bat
and just run it
but if you want to do something else
cd\ will get you to the root of c drive
cd.. (2 dots) will get you to one lower level of directory
Bold_Fortune
Nope. If I make it into a bat file, it doesn't work.
XtremeMaC
hmm maybe your windows cannot process the full paths
try them with
CODE
@echo off
echo Backing up folder and files...
cd\
md backup
xcopy C:\Progra~1\Common~1\MSSoap\*.* c:\backup\ /s /e /c /q /h
echo finished backup.
echo beginning removal of original...
rd C:\Progra~1\Common~1\MSSoap /s /q
echo removal complete


also it might be bc he didn't create the folder backup in root c
I added it...
IcemanND
what doesn't work, exactly? It worked great in my test.
XtremeMaC
u didn't create the backup folder I guess
no my bad xcopy creates it itself I forgot about that...
Bold_Fortune
Darn. Okay, I'm supposed to make the backup folder on C:\ ..right? What do I name it? Then I take that and save it as a bat file to my desktop ...right? Double-click on it, and it should work ...right?
IcemanND
save contents of code box above by extrememac to doit.cmd (if you are not using 2000 or xp, then doit.bat) wherever you want to keep it. you do not have to create any folders. then double click on the file and away you go.
Bold_Fortune
QUOTE (XtremeMaC @ Dec 13 2003, 01:20 AM)
hmm maybe your windows cannot process the full paths
try them with
CODE
@echo off
echo Backing up folder and files...
cd\
md backup
xcopy C:\Progra~1\Common~1\MSSoap\*.* c:\backup\ /s /e /c /q /h
echo finished backup.
echo beginning removal of original...
rd C:\Progra~1\Common~1\MSSoap /s /q
echo removal complete


also it might be bc he didn't create the folder backup in root c
I added it...

This one worked. But it only backed-up the contents of the MSSoap folder, not the folder itself. In other words it backed up Binaries, the sub-folder of MSSoap, and it's contents.
IcemanND
change c:\backup\ to c:\backup\MSSoap\

then c:\backup will contain a mssoap folder with everything inside it that was previously inside backup with the previous script.
Bold_Fortune
I new this would happen if we really got into it. So thanks for your patience, guys.

I'm lost again. "change c:\backup\ to c:\backup\MSSoap\"

Which line is that on? Here's what I copied:

@echo off
echo Backing up folder and files...
cd\
md backup
xcopy C:\Progra~1\Common~1\MSSoap\*.* c:\backup\ /s /e /c /q /h
echo finished backup.
echo beginning removal of original...
rd C:\Progra~1\Common~1\MSSoap /s /q
echo removal complete

One more thing. Could these lines be replaced for me with something I can understand a little better: "C:\Progra~1\Common~1\MSSoap\ " ? See, If I wanted use this bat file to for a different folder, I would not know how to insert it there. Can it read simply "C:\Program Files\Common Files\MSSoap" ?
IcemanND
ok, last try. There is only one c:\backup\ in the file. ?!?!?

this location is your destination, where it all gets backed up to. whatever you have there whether it is c:\backup\ or c:\backup\mssoap\ or c:\backup\myjunk\ in the xcopy line this is the destination. Just end it with a \ or it will ask you a question.

Now if you want to backup a diffewrent folder change
c:\progra~1\common~1\mssoap in then xcopy line and in the rd line. this is the source directory, what you are backing up and then removing.

the file is just a simple text file, open it in notepad.

QUOTE
Can it read simply "C:\Program Files\Common Files\MSSoap" ?

try it if it works then yes. May need to enclose it in " ".
Bold_Fortune
IcemanND, I don't think I can do this. I'll just request this and see if you will do it for me. Will you make what I need? I mean just make it. I'm having such a hard time understanding this.
Bold_Fortune
I think he got frustrated with me and left. I can understand that. Can any else make what I need and post it for me. I really don't understand all the explainations. I don't mean to frustrate anyone.
Bold_Fortune
I finally got it. Just took you guys 18 hours to get it through to me. This is what I finally came up with, and it is just what I wanted.

@echo off
echo Backing up folder and files...
cd\
md backup
xcopy "C:\Program Files\Common Files\MSSoap\"*.* c:\backup\MSSoap /s /e /c /q /h
echo finished backup.
echo beginning removal of original...
rd "C:\Program Files\Common Files\MSSoap" /s /q
echo removal complete

Figuring out the \" on the xcopy line, and the " with no slash before it on the rd line was a bit tricky for me. But I made a lucky guess.

Hey, thanks ever-so-much for your time and trouble. Even though you all seemed to walk away in the end. LOL. But I can understand your frustration with me. Thanks again.
LeveL
Wow this is where it all started huh.

I don't have Bold's link in my sig for nothing.

I can see how people made it incredibly awkward here explaining things to Bold.

But its 5 years ago so who cares.

Theres only one thing I could suggest to help - use variables not definite paths, because in reality a variable is a more definite path (safer really, if you ever want to use those batch files on another system where Windows might not be installed to C:)

So, example:

MOVE /Y "C:\Documents and Settings\USERNAME\Application Data\Microsoft\Credentials" "C:\MyBackup"

This could and in my opinion should say:

MOVE /Y "%APPDATA%\Microsoft\Credentials" "%SystemDrive%\MyBackup"

Thats about it.
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.