Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Need help wih a .bat file commands

13 Jun 2011   #1

Windows 7 Home Premium 32bit
 
 
Need help wih a .bat file commands

Im not sure if this is a grate place to ask this.. but... well Windows does speak DOS commands... well sorta

anyway, im trying to set up a batch file that would first transfer all the files and subfolders from "a" folder to "b" folder, and then would delete all the subfolders and files in "a" folder but it has to leave "a" folder undeleted. i wan to delete just all the files and subfolders inside. i searched forums for a few hours now, no luck.. all i came up with is this:
Code:
@echo off
xcopy /Y C:\Users\User\Desktop\a\*.* C:\Users\User\Desktop\b /s /q /f
del C:\Users\User\Desktop\a\*.* /s /q /f
ECHO Y | RD /s /q C:\Users\User\Desktop\a
exit
it does the job just.. it also deletes the "a" folder, witch is a bad thing

does anybody can help with this?

My System SpecsSystem Spec
.

13 Jun 2011   #2

Windows 7 Professional x64 SP1 ; Windows Server 2012 R2 Standard
 
 

I am going to leave this to one of your Developers although I know some Batch script commands I am unable to help you with this one

I shall notify a Developer to see if they can help you

Josh
My System SpecsSystem Spec
13 Jun 2011   #3

Windows 7 Home Premium 32bit
 
 

ok.. thanx
My System SpecsSystem Spec
.


13 Jun 2011   #4

Vista Home Premium x86 SP2
 
 

Hello!

I see that you are not copying empty subdirectories. Why is this? Do you want to use this as a way of removing subdirectories? Is there any reason why we can't just recreate 'a'?

Also, xcopy has been depreciated now. Any particular reason not to use robocopy, or does it just have too many options!?

And why does this need to be a batch file? Couldn't you just use explorer?

Thanks a lot!

Richard

P.S. mkdir "C:\Users\User\Desktop\a" will fix the issue? The whole batch file is a bit brittle though.
My System SpecsSystem Spec
13 Jun 2011   #5

Windows 7 Home Premium 32bit
 
 

Quote   Quote: Originally Posted by niemiro View Post
Hello!

I see that you are not copying empty subdirectories. Why is this? Do you want to use this as a way of removing subdirectories? Is there any reason why we can't just recreate 'a'?

Also, xcopy has been depreciated now. Any particular reason not to use robocopy, or does it just have too many options!?

And why does this need to be a batch file? Couldn't you just use explorer?

Thanks a lot!

Richard

P.S. mkdir "C:\Users\User\Desktop\a" will fix the issue? The whole batch file is a bit brittle though.
lol i cant find how to make this thing to copy empty subdirectories lol but oh well, thats not that big deal. well im a newbie at DOS commands.

emm.. what is robocopy command? lol and actually should be nice if all the commands would work in the xp machine to, now i need on Win 7, but later might on xp to.

and.. i need a batch file, cause im gonna make this run automatically when one my created setup.exe will finish actions, it will run this batch file to clean some mess lol

mkdir wont fix it, cause the the "a" folder haz to be a DESKTOP ;D yah... and i dint tested yet what will happen on actual desktop with this .bat , might crash? cause im pretty sure desktop is not the folder that can be deleted lol

yah my batch is brittle but im fine as long as it runs lol


Basically what i wanna do is, to make make somehow, move all the desktop folders and files and paste to a specific folder. to make desktop clean.
My System SpecsSystem Spec
13 Jun 2011   #6

Windows7 Pro 64bit SP-1; Windows XP Pro 32bit
 
 

SH-Soft - Tools -- RoboCopy Gui

Download is at the bottom of the page. I have never used it just providing the link.

Mike
My System SpecsSystem Spec
13 Jun 2011   #7

Windows 7 Pro x64 SP1
 
 

Quote   Quote: Originally Posted by nekonya View Post
Im not sure if this is a grate place to ask this.. but... well Windows does speak DOS commands... well sorta

anyway, im trying to set up a batch file that would first transfer all the files and subfolders from "a" folder to "b" folder, and then would delete all the subfolders and files in "a" folder but it has to leave "a" folder undeleted. i wan to delete just all the files and subfolders inside. i searched forums for a few hours now, no luck.. all i came up with is this:
Code:
@echo off
xcopy /Y C:\Users\User\Desktop\a\*.* C:\Users\User\Desktop\b /s /q /f
del C:\Users\User\Desktop\a\*.* /s /q /f
ECHO Y | RD /s /q C:\Users\User\Desktop\a
exit
it does the job just.. it also deletes the "a" folder, witch is a bad thing

does anybody can help with this?
The next to the last line echo Y | RD /s /q cusers\user\desktop\a
is supposed to delete the directory a on the desktop if there is one.
but the Q keeps it quiet
a better one would be

The Rd command removed the directory and all below it if the /s option
is used, EVEN the directory you specify.

What you might want to do is to add before that statment

CD c:\users\user\desktop\a
then do the rd *. /s /q

Dangerous but still should work.

As was said earlier removing directories with the /q option is really playing
with fire.

Rich

PS: Why do you want to remove the files and directories without any real confirmation that they were copied off???
My System SpecsSystem Spec
13 Jun 2011   #8

Windows 7 Home Premium 32bit
 
 

U mean, like this?:

Code:
@echo off
xcopy /Y C:\Users\User\Desktop\a\*.* C:\Users\Kei\b\ /s /q /f
del C:\Users\User\Desktop\a\*.* /s /q /f
CD c:\users\User\desktop\a
ECHO Y | RD /s C:\Users\User\Desktop\a
exit
well nothing changed, "a" disapears and all the stuff from "a" gots in "b". what CD does?

well "a" and "b" its just testing, the final thing will looks something like this:

Code:
@echo off
xcopy /Y %userprofile%\Desktop\*.* %userprofile%\DesktopFiles\  /s /q /f
del %userprofile%\Desktop\*.* /s /q /f
CD %userprofile%\Desktop
ECHO Y | RD /s %userprofile%\Desktop\
exit
i tested on the virtual mashine with the windows 7 and this batch, files where moved, but empty folders leaved. windows dint crashed. no errors appeared. thats good, but lots of empty folders where left on the desktop. how to make them delete to, to leave clean desktop? (well recycle bin will be anyways there cause its not rly in the desktop folder, but its ok)

and i wanna make this action quietly, cause im making a desktop theme pack, its like, setup will change wallpaper, glass color, install some themes for the apps. all works now, exept this desktop auto clean part...
i will mention in the rights agreement about desktop files moving lol, so i want to show to user as less installation messages / windows as possible. im trying to make this 1-2-3 easy user friendly installation.
My System SpecsSystem Spec
13 Jun 2011   #9

Windows 7 Pro x64 SP1
 
 

your code needs to be modified.

@echo offxcopy /Y C:\Users\User\Desktop\a\*.* C:\Users\Kei\b\ /s /q /fdel C:\Users\User\Desktop\a\*.* /s /q /fCD c:\users\User\desktop\aECHO Y | RD /s C:\Users\User\Desktop\aexitwell nothing changed, "a" dissapears and all the stuff from "a" gots in "b". what CD does?

I would recommend:
Just to SYA, I would make sure that there is a file in the A directory from the desktop named something
special like

c:\users\user\desktop\a\junk.txt

this way your code would be like this.
xcopy /Y C:\Users\User\Desktop\a\*.* C:\Users\Kei\b\ /s /q /f
then I would do a CD to
cd c:\users\user\desktop\a
if not exist junk.txt goto trouble.
rem you are now located in the A directory on the desktop of the user.
rd *. /q /y /s
rem: you are still in the A directory and there should not be any directories or files there..
goto end1
:trouble
echo something is wrong and you better correct it as junk.txt is not in the a directory.
:end1

this might help.
remember that the RD command removes the named directory as will as the ones below it.

Rich
My System SpecsSystem Spec
13 Jun 2011   #10

Windows 7 Home Premium 32bit
 
 

Quote   Quote: Originally Posted by richnrockville View Post
your code needs to be modified.

@echo offxcopy /Y C:\Users\User\Desktop\a\*.* C:\Users\Kei\b\ /s /q /fdel C:\Users\User\Desktop\a\*.* /s /q /fCD c:\users\User\desktop\aECHO Y | RD /s C:\Users\User\Desktop\aexitwell nothing changed, "a" dissapears and all the stuff from "a" gots in "b". what CD does?

I would recommend:
Just to SYA, I would make sure that there is a file in the A directory from the desktop named something
special like

c:\users\user\desktop\a\junk.txt

this way your code would be like this.
xcopy /Y C:\Users\User\Desktop\a\*.* C:\Users\Kei\b\ /s /q /f
then I would do a CD to
cd c:\users\user\desktop\a
if not exist junk.txt goto trouble.
rem you are now located in the A directory on the desktop of the user.
rd *. /q /y /s
rem: you are still in the A directory and there should not be any directories or files there..
goto end1
:trouble
echo something is wrong and you better correct it as junk.txt is not in the a directory.
:end1

this might help.
remember that the RD command removes the named directory as will as the ones below it.

Rich
ty for ur help, but to be honest, i barely understood what u just said ;D
i probably would be way better understanding if you would just write me a batch file ;D

look, here is the final project:
Code:
@echo off
xcopy /Y %userprofile%\Desktop\*.* %userprofile%\DesktopFiles\  /s /q /f
del %userprofile%\Desktop\*.* /s /q /f
ECHO Y | RD /s %userprofile%\Desktop\
the goal is: to make all the files and folders from curent user desktop move to folder called "DesktopFiles" witch one is placed in Windows user folder (when we hit the name on start, we get there) and leave no files and folder on desktop.

so, please fix my batch file and write me a correct one, so i can just copy and paste to test and edit
My System SpecsSystem Spec
Reply

 Need help wih a .bat file commands




Thread Tools



Similar help and support threads for2: Need help wih a .bat file commands
Thread Forum
How to do global commands General Discussion
Shortcut with 2 commands General Discussion
Solved Correct DOS commands might help Backup and Restore
Including some commands in an unatttend file Installation & Setup
Solved Bat commands.. General Discussion
Solved Windows Run Commands General Discussion
Commands in Windows 7 Tutorials

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 11:29 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33