I have BAT scripts which are nothing tricky and work fine on XP. But on Win 7, about 1 in 5 executions of mkdir following rmdir give a mystery Access Denied. E.g.
S:\TLIB importing\! Curtains\2 To process>rmdir temp3allout /s /q
S:\TLIB importing\! Curtains\2 To process>mkdir temp3allout
Access is denied.
After this, when I try in Explorer, it has no problem making that directory. Running thatBAT again usually succeeds.
Any idea what's going on here?
Win XP disc was a regular 2Gb drive. Win 7 disc is a 2Gb Intel RST RAID1 array with caching and flushing disabled http://i.imgur.com/Ohqkg2t.png .
This happens when the file system hasn't finished deleting the directory yet.
Sometimes this will happen synchronously, i.e., before the rmdir command completes, but sometimes there will be a very short but nonzero delay. (In XP it was always synchronous, IIRC.)
If possible, avoid deleting and immediately recreating directories; if you can't avoid it, you'll need to detect the failure and retry.
You should probably also test and if necessary retry the rmdir; sometimes rmdir runs into the same problem and fails to delete the entire directory tree.
Because that directory or file in that directory is open in some editor,first you have to close that file/directory from editor and then try.
These error usually comes when we create some directory and then delete it,but it is partially deleted and we create new directory with same name.
Related
I have a batch file that copies the most recent version of an access front-end file to the user's C: drive and then opens it from there.
For some users, the copy command causes the batch file to close, and I can't work out what could cause that. The file seems to copy, but the batch file just closes itself without any visible error messages.
I've used Pause to confirm that the failure happens at the Copy step, not the Run or the If.
This is Windows 7, I've tried it with Copy and Xcopy. The users with the issue say it's worked in the past, they all have access to the location being copied from (and to). Mapping the location doesn't seem to make any difference, and UNC paths work for most users so it's not that.
Deleting the existing files in C:\databases doesn't help.
if not exist "C:\Databases\" mkdir "C:\Databases"
copy "\\SERVER02\FINOPS\COMMAQR\DIGIHUB\1. Live Version\DIGIHUB v2.5.accdb" "C:\Databases\"
start [the file]
For 95%+ of users, the batch file copies the most recent version down and opens the file. For a handful, the batch file reaches the copy step and closes itself.
Does anyone know why this could happen, or alternatives to both Copy and XCopy that might not fail?
I am a bit troubled these days because I just started deleting C:/ on a production server.
I just wanted to remove c:/$Recycle.bin to clean some disk space.
But when I attempted to type $, I accidentally pressed Enter instead of shift, because these are very close buttons on my keyboard.
So the command went to delete C:/ .... :( Luckily, I didn't run the cmd with administrator rights and I only removed a few GB because of permissions.
I can recover the wasted files because the machine is protected with backups.
But how may I know what files have been deleted and what havn't?
Does anybody know in what order RD command (remove directory) processes the files / folders ? Alphabetically or...
I'd be happy if someone can help.
I'm kind of new to batch scripting.
As a newbie I find both both of them useful while scripting
What are the key differences between xcopy and robocopy?
Robocopy replaces XCopy in the newer versions of windows
Uses Mirroring, XCopy does not
Has a /RH option to allow a set time for the copy to run
Has a /MON:n option to check differences in files
Copies over more file attributes than XCopy
Yes i agree with Mark Setchell, They are both crap. (brought to you by Microsoft)
UPDATE:
XCopy return codes:
0 - Files were copied without error.
1 - No files were found to copy.
2 - The user pressed CTRL+C to terminate xcopy. enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
5 - Disk write error occurred.
Robocopy returns codes:
0 - No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
1 - One or more files were copied successfully (that is, new files have arrived).
2 - Some Extra files or directories were detected. No files were copied Examine the output log for details.
3 - (2+1) Some files were copied. Additional files were present. No failure was encountered.
4 - Some Mismatched files or directories were detected. Examine the output log. Some housekeeping may be needed.
5 - (4+1) Some files were copied. Some files were mismatched. No failure was encountered.
6 - (4+2) Additional files and mismatched files exist. No files were copied and no failures were encountered. This means that the files already exist in the destination directory
7 - (4+1+2) Files were copied, a file mismatch was present, and additional files were present.
8 - Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further.
16 - Serious error. Robocopy did not copy any files. Either a usage error or an error due to insufficient access privileges on the source or destination directories.
There is more details on Robocopy return values here: http://ss64.com/nt/robocopy-exit.html
The most important difference is that robocopy will (usually) retry when an error occurs, while xcopy will not. In most cases, that makes robocopy far more suitable for use in a script.
Addendum: for completeness, there is one known edge case issue with robocopy; it may silently fail to copy files or directories whose names contain invalid UTF-16 sequences. If that's a problem for you, you may need to look at third-party tools, or write your own.
The differences I could see is that Robocopy has a lot more options, but I didn't find any of them particularly helpful unless I'm doing something special.
I did some benchmarking of several copy routines and found XCOPY and ROBOCOPY to be the fastest, but to my surprise, XCOPY consistently edged out Robocopy.
It's ironic that robocopy retries a copy that fails, but it also failed a lot in my benchmark tests, where xcopy never did.
I did full file (byte by byte) file compares after my benchmark tests.
Here are the switches I used with robocopy in my tests:
**"/E /R:1 /W:1 /NP /NFL /NDL"**.
If anyone knows a faster combination (other than removing /E, which I need), I'd love to hear.
Another interesting/disappointing thing with robocopy is that if a copy does fail, by default it retries 1,000,000 times with a 30 second delay between each try. If you are running a long batch file unattended, you may be very disappointed when you come back after a few hours to find it's still trying to copy a particular file.
The /R and /W switches let you change this behavior.
With /R you can tell it how many times to retry,
/W let's you specify the wait time before retries.
If there's a way to attach files here, I can share my results.
My tests were all done on the same computer and
copied files from one external drive to another external,
both on USB 3.0 ports.
I also included FastCopy and Windows Copy in my tests and each test was run 10 times. Note, the differences were pretty significant. The 95% confidence intervals had no overlap.
Its painful to hear people are still suffering at the hands of
*{COPY} whatever the version.
I am a seasoned batch and Bash script writer and I recommend rsync , you can run this within cygwin (cygwin.org) or you can locate some binaries floating around .
and you can redirect output to 2>&1 to some log file like out.log for later analysing.
Good luck people its time to love life again .
=M. Kaan=
I have written lot of scripts to automate daily backups etc. Previously I used XCopy and then moved to Robocopy. Anyways Robocopy and XCopy both are frequently used in terms of file transfers in Windows. Robocopy stands for Robust File Copy. All type of huge file copying both these commands are used but Robocopy has added options which makes copying easier as well as for debugging purposes.
Having said that lets talk about features between these two.
Robocopy becomes handy for mirroring or synchronizing directories. It
also checks the files in the destination directory against the files
to be copied and doesn't waste time copying unchanged files.
Just like myself, if you are into automation to take daily backups
etc, "Run Hours - /RH" becomes very useful without any interactions.
This is supported by Robocopy. It allows you to set when copies
should be done rather than the time of the command as with XCopy. You
will see robocopy.exe process in task list since it will run
background to monitor clock to execute when time is right to copy.
Robocopy supports file and directory monitoring with the "/MON" or
"/MOT" commands.
Robocopy gives extra support for copying over the "archive" attribute
on files, it supports copying over all attributes including
timestamps, security, owner, and auditing information.
Hope this helps you.
They are both rubbish! XCOPY was older and unreliable, so Microsoft replaced it with ROBOCOPY, which is still rubbish.
http://answers.microsoft.com/en-us/windows/forum/windows_8-files/robocopy-appears-to-be-broken-in-windows-8/9a7634c4-3a9d-4f2d-97ae-093002a638a9
Don't worry though, it is a long-standing tradition that was started by the original COPY command, which to this day, still needs the /B switch to get it to actually copy properly!
if I do
rm_rf('somewhere')
mkdir('somewhere')
every so often, the mkdir throws a Permission Denined. Is this because the rm_rf runs asynchronously and sometimes hasnt finished deleting the dir before the mkdir runs?
How do I make it block until its completed the delete?
running this on Windows btw.
Thanks
Sounds like a feature of NTFS, see Microsoft Suppport:
This file is in a state known as pending deletion. This file has been
deleted, but there are still handles open to it. NTFS will wait until
all handles to this file are closed before updating the index. If an
attempt is made to access the file, however, NTFS will deny the
attempt. Because the file is listed in the index, but is effectively
deleted, you can see the file but you cannot access it.
And looking at the solutions, I don't think there is much to do other than to wait and retry.
rm_rf is synchronous, as any other usual ruby method.
and if it was'nt then you'd probably get a Errno::EEXIST error, but you are getting 'permission denied'.
as a workaround try to insert small delay, like sleep(0.1) between rm_rf & mkdir
I faced this error too and renamed it first as a workaround:
build_dir.directory? &&
build_dir.rename(old_build_dir) &&
FileUtils.rm_rf(old_build_dir)
build_dir.mkdir
(build_dir and old_build_dir are Pathname objects)
Not perfect but better than a random sleep.
I don't seem to have this problem on my home laptop with Windows XP, but then I don't do much work there.
On my work laptop, with Windows XP, I have a problem deleting directories when it has directories that contain .svn directories. When it does eventually work, I have the same issue emptying the Recycle bin. The pop-up window says "Cannot remove folder text-base: The directory is not empty" or prop-base or other folder under .svn
This continued to happen after I changed config of TortoiseSVN to stop the TSVN cache process from running and after a reboot of the system.
Multiple tries will eventually get it done. But it is a huge annoyance because there are other issues I'm trying to fix, so I'm hoping it is related.
'Connected Backup PC' also runs on the laptop and the real problem is that cygwin commands don't always work. So I keep thinking the dot files and dot directories have something to do with both problems and/or the backup or other process scanning the directories is doing it. But I've run out of ideas of what to try or how to identify the problem further.
You don't need to reboot; just open Task Manager and kill TSVNCache.exe.
This is safe, too. It's designed so you can kill it and it will automatically restart when needed.
(As a result of the auto-restart, note that browsing some SVN folders in Explorer, File-Open dialogs, etc. may cause TSVNCache.exe to restart. Keep an eye on Task Manager.)
Tortoise SVN is great but I have found that TSVNCache.exe can hold on to locks and get in the way at times. (Sometimes justified, sometimes not.) As a result, for some automated scripts I run I include commands to kill TSVNCache.exe as part of the scripts so it doesn't get in the way. That's only worth doing if it's an operation you perform often, though.
You can try a few things:
Since you are getting this error frequently, you can use handle.exe from sysinternals to check which process currently have open handles for the .svn\* directory. If handle utility tells you about any process, try stopping that process and then delete the directories.
Error while deleting from recycle bin: In simple terms, when a file is sent to recycle bin after deleting, it is not actually deleted, rather, a few manipulations are done in directory hierarchy (file system level) to avoid showing the file while browsing content of a folder. So If you happen to resolve the problem mentioned in comment#1, you will not get this error probably.
Cygwin command not working: Running a cygwin command on windows requires (in particular) cygwin1.dll, which is known to be shipped with other programs (eg: CopSsh, some version of svn clients etc...) as well. If there is any mismatch in the version of cygwin1.dll, cygwin commands won't work. Try searching for cygwin1.dll on your computer and try to resolve version conflicts (if any).
did you ever do mkpasswd and mkgroup for cygwin? If you're using cygwin from the command line you are pretty much guaranteed to have file system permissions issues. and you have to read a little to fix it.
http://cygwin.com/cygwin-ug-net/ntsec.html
Try this answer from me. Although it's given for TortioseGit instead of TortoiseSVN, the handling is the same:
disable the status cache (i.e. prevent the TSVNCache.exe from accessing the .svn folders continuously)
delete what you have to delete
enable the status cache to get updated overlays again
I have just experienced this problem (or similar)
I am using tortoise 1.6.7
To fix it I went to 'Tortoise Settings' from the tortoise context menu.
from there select "Icon Overlays" in the tree widget.
In the icon overlays page, I entered the path that was giving me angst into the "exclude paths:"and tortoise no longer holds that directory handle.
This is a directory that is often deleted by a process other than explorer.
Since what it appears that you are trying to do is export the repository from SVN, why not use the export functionality with TortoiseSVN. This removes all .svn directories from the generated 'working copy'.Cmdline: http://svnbook.red-bean.com/en/1.0/re10.html
If you want to delete all sub folders named .svn in windows
then create batch file with this content:
for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *.svn') do (
rd /s /q "%%i"
)
save it in a file del_All_Dot_SVN_Folders.cmd . Run it. Your done.
Thanks to http://www.axelscript.com/2008/03/11/delete-all-svn-files-in-windows/
Remember the above code has .svn whereas the code in the link has only *svn so its better
to have the .svn to not accidentally have undesired effect.