Windows 7 Copy to c:\ doesn't work with batch file

Discussion in 'Programming and Scripting' started by Glip, Sep 17, 2009.

  1. Dave Swindell

    Dave Swindell New Member

    Joined:
    Oct 25, 2009
    Messages:
    12
    Likes Received:
    0
    Bat to exe converter will not download on my Windows 7. It says the zip file is invalid.

    I have the same problem with XCOPY described in this thread.

    I have used XCOPY in similar .BAT files on all my PCs from DOS through every Windows to Vista. It refuses to work on 7.

    The code in the .BAT file is as follows :-

    echo on
    xcopy "C:\Users\David\My Documents\*.*" "DAVID_BACKUPS\CHANGES_Documents" /s /m
    echo off
    echo on
    xcopy "C:\Users\David\My Pictures\*.*" "DAVID_BACKUPS\CHANGES_Pictures" /s /m
    echo off
    echo on
    xcopy "C:\Users\David\My Music\*.*" "DAVID_BACKUPS\CHANGES_Music" /s /m
    echo off
    echo on
    xcopy "C:\Users\David\Contacts\*.*" "DAVID_BACKUPS\CONTACTS" /s /m
    echo off
    pause

    The way I and my family use it, on all our PCs, is as follows :-

    Plug in the backup device (nowadays a USB external drive but in the past it has been a series of 3.5 inch disks)

    Open the device and click on .BAT file BACKUP_ALL.BAT

    It should then copy all the files that have changed since the last time the .BAT file was run onto the necesary folders in "DAVIDS_BACKUPS" on the current drive - that is those with their ARCHIVE attributes set on. But it only works with "Contacts", with all the other XCOPIES is says :-

    File not found - *.*
    0 File(s) copied

    even though all the ARCHIVE attributes on all the files are most certainly set ON.

    I need this to work every time for all my users. It is unreasonable to have to go to heightened Administrator levels. My users are essentially naive.

    All further help most gratefully received
     
  2. tblount

    tblount New Member

    Joined:
    Sep 27, 2009
    Messages:
    3,537
    Likes Received:
    64
    You can copy anything you want to the root .....

    The reason your batch file doesn't work is because its not running in the same folder with "somefile" so it can't find it.


    INCLUDE the path to "somefile" and it will work from anywhere.. on any drive.. for example

    copy c:\windows\system32\*.txt c:\

    MAKE SURE your batch file uses \ NOT / It's easy to get them confused.

    I pasted the above command to a command prompt while in my temp folder and it worked... there is only one text file in the system32 folder.

    NOTE... if you copy a file with read only or system attibutes ON ... then try again it won't overwrite it.... you will get an ACCESS DENIED message... unless you learn to use xcopy with the parameters to override the protections.

    Hundreds of system files have TrustedInstaller protection and even if you are in the administrator's group you may not have permission to copy, rename, overwrite or delete them.
     
  3. tblount

    tblount New Member

    Joined:
    Sep 27, 2009
    Messages:
    3,537
    Likes Received:
    64
    YES.. I was sad to see that bat to exe doesn't work consistently on 7.... it does work sometimes but usually fails.





    Ok... let me try to sort this all out and explain some things. First, almost everything in YOUR userprofile will be blocked from another user... IF it wasn't then there is not much need for a computer to have separate user logons. It's a privacy issue. You may not want your kids to copy your porn.

    Second.... the reason ONLY the Contacts files are copied is because it's the only correct path.

    Notice every OTHER folder says "My" whatever.... For some reason windows explorer is DISPLAYING "MY" before pictures, documents and pictures.

    HOWEVER... stay with me here...... if you actually go to the command prompt in \users\david folder and type and enter Dir

    You will see the REAL folder name is just Pictures, Documents and Music so... your xcopy path is INCORRECT for them.

    Do I need to fix it? You should be able to take it from here.. just take out "my"

    You don't need any of those echo commands.

    You can also use %userprofile% so the same batch file will work for everyone -- go into their profile and backup their new photos etc ..rather than just work with \users\dave .. however it WILL put them all in the same target folder because %userprofile% INCLUDES C:


    Your example would never backup to a usb drive because you have no target drive letter. It will only create the folders and copy to your C:\ drive

    I would use /d rather than /m it's more reliable than fliping the archive attribute.

    You can also use . rather than *.* if you want to.

    I should be getting paid for this! Where is my gold star?
     
    #23 tblount, Oct 26, 2009
    Last edited: Oct 26, 2009
  4. tblount

    tblount New Member

    Joined:
    Sep 27, 2009
    Messages:
    3,537
    Likes Received:
    64
    Oh.. one moe thing.... If your batch file is run FROM the usb ... or IF it changes to the usb.. then the backup folders will be created on the usb.

    I would first check to see if the usb drive was present......if not it would just exit so that the rest of the batch file wouldn't back up everything to the c: drive

    I think this is the basic command

    if not exist e:\. echo There is no flashdrive in E:

    instead of "echo" you might say "goto end"

    :end

    would be the last line of your batch file.. causing it to jump over the copy commands that have an incorrect target drive.
     
  5. Dave Swindell

    Dave Swindell New Member

    Joined:
    Oct 25, 2009
    Messages:
    12
    Likes Received:
    0
    ".... the reason ONLY the Contacts files are copied is because it's the only correct path."

    "..... the REAL folder name is just Pictures, Documents and Music so... your xcopy path is INCORRECT for them."


    Many thanks for this advice, and information. What an utter embuggerance that M&oft have reintroduced this annoying, and IMHO rather silly, "My ..." business. Your hint solved the problem immediately.


    "Your example would never backup to a usb drive because you have no target drive letter. It will only create the folders and copy to your C:\ drive"


    It does work because the .BAT file is run FROM the USB drive. The whole point is that my naive user population just need to plug in the USB drive and click on the BACKUP batch file. By default it copies to the current drive.


    "I would use /d rather than /m it's more reliable than fliping the archive attribute."


    But this would defeat the object. I am only backing up those things that have changed since the last backup. The whole "Pictures", "Documents" and "Music" folders are copied wholesale every now and then to the same drive, a process that can take quite literally hours because I'm a notorious hoarder. It wouldn't be at all friendly to do this every day. But backing up just the daily changes is a matter of seconds, or minutes at the most.

    This backup method saved my bacon when my laptop died on me last week. I copied the full folder backups to the new laptop, then the things that had changed since those full folder backups were done, and reviewed those places where I had changed folder and file names and moved them around, or deleted them, and I am working again. The only problems have been the oddities of Windows 7, which I have overcome with your excellent advice, and reloading previously downloaded software. I've lost 18 months of emails, but I still hold out hopes for recovering them.

    Many, many thanks again, and consider your gold star well earned.
     
  6. tblount

    tblount New Member

    Joined:
    Sep 27, 2009
    Messages:
    3,537
    Likes Received:
    64
    Welcome.

    yeah... I remember that and wrote about it in the next message.... but I don't think it will work for a user with less than administator access... since one user's personal documents images etc are protected from another.

    I like /d because it compares dates and there is less prompting (unless you put /y on the command line to answer yes to all the prompts) If your archive bits gets turned on in the sorce folders, when you use /m it will be overwiting same same files in the tagret.. but /d will notice the date is the same and just skip them.


    You know you can boot to a command promp from an install disk and xcopy just about everything in all user's profiles to a backup target. If windows is loaded MOST of the user's profile files are restricted. Xcopy still appears to have a bug that causes it to sometimes fail on folders with spaces in the file names. For some strange reason it will copy most of them but there is one folder that it can't get. I just use Acronis True Image and make a new clone from time to time.... it takes only a few minutes and makes the backup drive bootable.
     
    #26 tblount, Oct 29, 2009
    Last edited: Oct 29, 2009
  7. Tepid

    Tepid New Member

    Joined:
    Jun 11, 2009
    Messages:
    1,344
    Likes Received:
    38
    There is no substitute for a real Back up program (ie. Acronis). There just isn't. However......

    I say again,, you can still try using iexpress as an alternative to bat to exe.

    I use iexpress for just about all my batch scripting, to have a simple contained autorun sequence.
    I have tested the ability to copy files directly to the C: drive with it and it works. I have not tested the other scenarios presented here.

    But, I would just tell you to get a program that will actually work better than using batch files for backing up.
    Just because something can be done, doesn't mean it's a good idea.
     
  8. pweegar

    pweegar New Member

    Joined:
    Oct 30, 2009
    Messages:
    36
    Likes Received:
    2

    Have you tried turning off the UAC????? That may fix your admin problems. AND your not really the true Administrator, just as in Vista. Unless you have a very good reason to do so, you shouldn't be running as the true Admin. IG you really want to learn how to use the Admin account in Win7, google it. There is a ton of info out there.
     
  9. pister007

    pister007 New Member

    Joined:
    Jun 4, 2012
    Messages:
    2
    Likes Received:
    0


    No one seems to have given a correct solution to the original problem. Disabling UAC completely as some have suggested will work but is not recommended. I had the same problem copying a file using xcopy.

    syntax: XCOPY file.txt C:\

    Here file.txt is in the same folder as the batch file. If I just ran the batch file, it would give a "access denied". This is the correct response as one would need elevated privileges to copy to c:\ . If I ran it with admin privileges (using "Run as administrator" from context menu), a "file not found" error is given. After much investigation I found that when the batch file is run as admin, the working directory changes to C:\Windows\System32 (where of course file.txt cannot be found, hence the "file not found" error).

    We need to change the location to the folder in which the batch file is located. This can be done by adding these two lines at the top of the script:
    This will change the current directory to the location of the .bat file.

    How it works:

    @setlocal enableextensions - controls the visibility of environment variables and enables cmd extensions.

    @cd /d "%~dp0" - Changes the current directory to %~dp0 which is a special batch parameter modifier that expands to the drive and directory that batch file is located in.

    %0 expands to the full path and file name of the batch file, adding the ~dp modifier in the middle to make %~dp0 reduces the %0 value to just the drive and path.

    To know more about modifiers:

    Now the xcopy command works with no problems.
     
    #29 pister007, Jun 4, 2012
    Last edited: Jun 4, 2012

Share This Page

Loading...