Need help wih a .bat file commands

Page 1 of 2 12 LastLast

  1. Posts : 71
    Windows 7 Home Premium 32bit
       #1

    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 Computer


  2. Posts : 2,298
    Windows 7 Professional x64 SP1 ; Windows Server 2012 R2 Standard
       #2

    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


  3. Posts : 71
    Windows 7 Home Premium 32bit
    Thread Starter
       #3

    ok.. thanx
      My Computer


  4. Posts : 908
    Vista Home Premium x86 SP2
       #4

    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 Computer


  5. Posts : 71
    Windows 7 Home Premium 32bit
    Thread Starter
       #5

    niemiro said:
    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 Computer


  6. Posts : 6,349
    Windows7 Pro 64bit SP-1; Windows XP Pro 32bit
       #6

    SH-Soft - Tools -- RoboCopy Gui

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

    Mike
      My Computer


  7. Posts : 1,800
    Windows 7 Pro x64 SP1
       #7

    nekonya said:
    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 Computer


  8. Posts : 71
    Windows 7 Home Premium 32bit
    Thread Starter
       #8

    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 by nekonya; 13 Jun 2011 at 14:57.
      My Computer


  9. Posts : 1,800
    Windows 7 Pro x64 SP1
       #9

    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


  10. Posts : 71
    Windows 7 Home Premium 32bit
    Thread Starter
       #10

    richnrockville said:
    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


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About 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 17:47.
Find Us