1.

Solve : Batch code works in XP but not in Win7?

Answer»

The following line out of my backup batch, that saves 20 copies of a particularly important file, has worked well for years in XP. However it fails to work in Win7. Any Pointers please.

setlocal
set source=S:\WebSiteBaks
pushd "%source%"
for /f "skip=20 delims=" %%a in ('dir /b /a:d /o:-d 2^>NUL') do rmdir /s /q "%%a"
popd

Many thanks, Mal

Quote from: MalA on November 28, 2013, 11:02:30 AM

The following line out of my backup batch, that saves 20 copies of a particularly important file, has worked well for years in XP. However it fails to work in Win7. Any Pointers please.

It doesn't save 20 copies of a file. It deletes folders.

What does it do in XP that it doesn't do in Win 7?Sorry, perhaps I should have described the whole batch file in full. Here goes

When the whole file runs in XP, it backs up a folder in C:\ that contains what to me is important data about my website, that is constantly changing. First it copies the whole folder and sub folders, then it renames that copy to be file+date+time. Then it deletes more than 20 copies of those renamed folders, so my HDD doesn't get full.
And it has worked well for quite some time.

It is the last bit, the DELETING bit that is not working in Win7, where it runs though all the contained files in the folders to be deleted, and PIPES them as "Access is Denied"

Any chance that you can help please - Mal
Quote from: MalA on November 30, 2013, 04:45:02 AM
It is the last bit, the deleting bit that is not working in Win7, where it runs though all the contained files in the folders to be deleted, and pipes them as "Access is Denied"

"Access is denied" could be caused by Windows 7's UAC (User Account Control), the lack of administrative privileges, or the file you're trying to delete could still be in use.I would also set up the batch file to "run as admin" in preferences if its not a file in use issue."Access is Denied"
comes also when another program has the file open.
The below link shows it can happen even if you try bop open a folder.
http://support.microsoft.com/kb/810881

NOTE: The issue is specific to XP and applies when you re-install XP. This is a must read for anyone wishing to continue using XP as their OS.Quote from: MalA on November 30, 2013, 04:45:02 AM
When the whole file runs in XP, it backs up a folder in C:\

It is the last bit, the deleting bit that is not working in Win7, where it runs though all the contained files in the folders to be deleted, and pipes them as "Access is Denied"

Later versions of Windows don't allow users access to c:\ without Admin perrmissions, even if UAC is turned off.

Pick the "%userprofile%\desktop\tempfolder" and it should work fine.foxidrive, Thanks for correcting me.His problem is in Windows 7, not in XP. OOPS.
Here is a general article on UAC in Windows.
http://en.wikipedia.org/wiki/User_Account_Control
Quote
... MALWARE should be kept from compromising the operating system. In other words, a user account may have ADMINISTRATOR privileges assigned to it, but applications that the user runs do not inherit those privileges unless they are approved beforehand or the user explicitly authorize
Writing to the root of the system drive is forbidden, just as foxdrive stated.


Discussion

No Comment Found