Need help wih a .bat file commands

nekonya

New member
Member
Local time
7:54 PM
Messages
71
Im not sure if this is a grate place to ask this.. but... well Windows does speak DOS commands... well sorta :D

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 Computer My Computer

OS
Windows 7 Home Premium 32bit
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 Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Built
OS
Windows 7 Professional x64 SP1 ; Windows Server 2012 R2 Standard
CPU
Intel Core i5 2400 @ 3.10GHz
Motherboard
Foxconn H67MP-S/-V/H67MP
Memory
8.0GB DDR3 @ 665MHz (2GBx4)
Graphics Card(s)
AMD Radeon HD 6870
Sound Card
Realtek High Definition Audio
Monitor(s) Displays
AOC 2243W & SMB1930NW
Screen Resolution
1440x900 & 1920x1080
Hard Drives
977GB Seagate ST31000524AS ATA Drive (SATA)
250GB WD iSCSI attached Drive
PSU
750W Gaming PSU
Case
Novatech Night
Cooling
Fan
Keyboard
Dell Standard PS/2 Keyboard
Mouse
R.A.T 07 Gaming Mouse
Internet Speed
Download: 10 Mbps Ping: 30ms Upload: 0.81 Mbps
Browser
Google Chrome
Other Info
Optiarc DVD RW AD-5260S ATA Device
ok.. thanx
 

My Computer My Computer

OS
Windows 7 Home Premium 32bit
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'? :p

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 Computer My Computer

Computer Manufacturer/Model Number
Dell XPS 420
OS
Vista Home Premium x86 SP2
CPU
Intel Core 2 Quad Q9300 2.50GHz
Motherboard
Stock Dell 0TP406
Memory
4 gb (DDR2 800) 400MHz
Graphics Card(s)
ATI Radeon HD 3870 (512 MBytes)
Monitor(s) Displays
1 x Dell 2007FP and 1 x (old) Sonic flat screen
Screen Resolution
1600 x 1200 and 1280 x 1204
Hard Drives
1 x 640Gb (SATA 300) Western Digital: WDC WD6400AAKS-75A7B0 1 x 1Tb (SATA 600) Western Digital: Caviar Black, SATA 6GB/S, 64Mb cache, 8ms Western Digital: WDC WD1002FAEX-00Z3A0 ATA Device
Case
Dell XPS 420
Cooling
Stock Fan
Keyboard
Dell Bluetooth
Mouse
Advent Optical ADE-WG01 (colour change light up)
Internet Speed
Varies from 10kb/s to 170kb/s. So unreliable it is not funny
Other Info
ASUS USB 3.0 5Gbps/SATA 6Gbps - PCI-Express Combo Controller Card (U3S6)
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'? :p

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 Computer My Computer

OS
Windows 7 Home Premium 32bit

My Computer My Computer

Computer Manufacturer/Model Number
Hopalong/ Godzilla
OS
Windows7 Pro 64bit SP-1; Windows XP Pro 32bit
CPU
Intel Core i7-870 Lynnfield 2.93GHz LGA 1156 95W Quad-Core
Motherboard
ASUS P7P55D-E PRO
Memory
8GB@1400MHz Crucial Ballistix DDR3-1600 4x2GB
Graphics Card(s)
ASUS ENGTX460 DirectCU/2DI/1GD5 1GB 256-bit GDDR5
Sound Card
VIA Onboard
Monitor(s) Displays
Asus VS248H-P 24"; Samsung SyncMaster 941BW 19"ws
Screen Resolution
1920x1080; 1440x900
Hard Drives
Samsung 830 120GB SSD
Intel 320 120GB SSD
Western Digital Caviar Black WD7501AALS 750GB 7200 RPM SATA 3.0Gb/s
Western Digital Caviar Black WD6401AALS 640GB 7200 RPM SATA 3.0Gb/s
PSU
COOLER MASTER Silent Pro RS850-AMBAJ3-US 850W Modular
Case
COOLER MASTER HAF 932 RC-932-KKN5-GP Black
Cooling
Scythe "Mugen-2 Rev.B" (2 ScytheKaze-Jyuni PWM fans)
Keyboard
Logitech K-320
Mouse
Kensington
Antivirus
Avast Inernet Suite
Browser
IE 9 ; Chrome
Im not sure if this is a grate place to ask this.. but... well Windows does speak DOS commands... well sorta :D

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 Computer My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Laptop Qosimo X870
OS
Windows 7 Pro x64 SP1
CPU
Intel Core I7
Motherboard
Toshiba Qosmio
Memory
16 Gigs
Graphics Card(s)
NVIDIA GeForce GTX 670M
Monitor(s) Displays
17.7" laptop
Screen Resolution
1600 x 900
Hard Drives
256 Gig SanDisk SSD for C
256 Gig Intel SSD for D
Internet Speed
50/25 FIOS
Antivirus
Vipre (all you can eat for 10 machines)
Browser
IE and FF
Other Info
I have dos 6.22, wfwg 3.11, win98, 2000 and xp VHD's available for testing. MS's Virtual PC works great.
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.
 
Last edited:

My Computer My Computer

OS
Windows 7 Home Premium 32bit
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 Computer My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Laptop Qosimo X870
OS
Windows 7 Pro x64 SP1
CPU
Intel Core I7
Motherboard
Toshiba Qosmio
Memory
16 Gigs
Graphics Card(s)
NVIDIA GeForce GTX 670M
Monitor(s) Displays
17.7" laptop
Screen Resolution
1600 x 900
Hard Drives
256 Gig SanDisk SSD for C
256 Gig Intel SSD for D
Internet Speed
50/25 FIOS
Antivirus
Vipre (all you can eat for 10 machines)
Browser
IE and FF
Other Info
I have dos 6.22, wfwg 3.11, win98, 2000 and xp VHD's available for testing. MS's Virtual PC works great.
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 Computer My Computer

OS
Windows 7 Home Premium 32bit
Ok OK, i almost managed to work ;o

here is how it looks like now:

Code:
@echo off
xcopy /Y %userprofile%\Desktop\*.* %userprofile%\DesktopFiles\  /s /q /f

c:
cd\ 
cd "%userprofile%\Desktop"
dir *.* /b -o:d | find /v "." > \dirs.txt
for /f "tokens=*" %%a in (\dirs.txt) do call :DelFiles "%%a"
del \dirs.txt
exit /b

:DelFiles %1
set Flag=0
if %1=="All Users" set Flag=1
if %1=="Administrator" set Flag=1
if %1=="CurentUser" set Flag=1
if "%Flag%"=="0" (
cd %1
attrib *.* -r /s
cd..
rem change rd %1 /s /q
rem for no confirmation
rd %1 /s
)
del %userprofile%\Desktop\*.* /s /q /f

the only issue is that every time when finds folder, now it keeps ask me or i do wanna delete this folder Y/N?

please tell me what to correct in this code to stop it ask me for Y/N and just pick Y automatically :)
 

My Computer My Computer

OS
Windows 7 Home Premium 32bit
newermind, i figured out myself.. it works now like a charm. if anyone needs this desktop .bat for some reason, pm me :)
 

My Computer My Computer

OS
Windows 7 Home Premium 32bit
Back
Top