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

Glip

New Member
Joined
Sep 17, 2009
Messages
12
I have a little strange problem under Windows 7 x64 using the copy command at the command prompt.

If I enter the following command at an elevated command prompt:

copy somefile c:\

it copies the file somefile to c:\. Now when I create a batch file from this command and run it with admin privileges it says it cannot find the file! Also, a strange thing is that when I run the batch file without administrator privileges it properly says 'access denied', so it can find it then, which is correct because you can't just write something to the C root.

Can someone verify and possibly resolve this?

Note this is all with UAC set to standard.
 


Last edited:
Solution
Bat to exe converter will not download on my Windows 7. It says the zip file is invalid.

YES.. I was sad to see that bat to exe doesn't work consistently on 7.... it does work sometimes but usually fails.




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...
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
 


I have a little strange problem under Windows 7 x64 using the copy command at the command prompt.

If I enter the following command at an elevated command prompt:

copy somefile c:\

it copies the file somefile to c:\. Now when I create a batch file from this command and run it with admin privileges it says it cannot find the file! Also, a strange thing is that when I run the batch file without administrator privileges it properly says 'access denied', so it can find it then, which is correct because you can't just write something to the C root.

Can someone verify and possibly resolve this?

Note this is all with UAC set to standard.

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.
 


Bat to exe converter will not download on my Windows 7. It says the zip file is invalid.

YES.. I was sad to see that bat to exe doesn't work consistently on 7.... it does work sometimes but usually fails.




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


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?
 


Last edited:
Solution
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.
 


".... 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.
 


".... 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.

Welcome.

"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.

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 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.

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.


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.

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.
 


Last edited:
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.
 


W7 protection i think. this crappy OS takes away more then it gives i think.
Even if u are administrator, u still cannot fully use anything u want in anyway u need.
As my example shows u cant copy files anywhere u want using CMD, what the hell is up with that ?
What kind of administrator do i have to be to be able to do what administrator should be able to do (everything)

I coded a program and had another execution issue, looks like windows 7 doenst transfer permissions to files correctly if this file was executed using shortcuts that were executed by another application.
For example u have a shotrcut leading to program that executes another program. u execute this shortcut using yet another program and u have a problem, the final destination is not executed somenow, yet all program functions worked. To fix it i had to go back to Windows XP and i love it :)

TO be hones man if u realy need something to bo copied to where u want it, use that bat to exe converter i gave u link to and compile using 1 simple option (add administrator manifest). This will solve ton of problems. In fact it works so great that it even lets o owerwrite system files such as dll's ad any other. To bad W7 wont let u do it unless u are some kind of super duper administrator or something.
In fact it would solve my problem but my script is to complex to run in CMD, so i had to code it in language.

Good luck
CMD rocks


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.
 


I have a little strange problem under Windows 7 x64 using the copy command at the command prompt.

If I enter the following command at an elevated command prompt:

copy somefile c:\

it copies the file somefile to c:\. Now when I create a batch file from this command and run it with admin privileges it says it cannot find the file! Also, a strange thing is that when I run the batch file without administrator privileges it properly says 'access denied', so it can find it then, which is correct because you can't just write something to the C root.

Can someone verify and possibly resolve this?

Note this is all with UAC set to standard.



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:
@setlocal enableextensions
@cd /d "%~dp0"
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:
Link Removed due to 404 Error


Now the xcopy command works with no problems.
 


Last edited:
Back
Top