I tried robocopy to test copy a single file from a folder to the desktop, and then many files from the desktop disappeared (not hidden).
Now I am desperate to retrieve those files.
I used the script
ROBOCOPY "C:\Users\frank\Desktop\New" "C:\Users\frank\Desktop" /mir
in a txt file and renamed it to .bat.
Then i ran it as admin.
A prompt then opened with many file names rushing past until i closed it.
Now many files are missing from the desktop.
I have tried to research what happened and only came up with cases where robocopy set the copied files to "hidden". But i have set the desktop folder attributes to "show" (it was set to hidden) and they are still missing.
The single file in the "new" folder i was trying to copy over, did not move.
I don't know if this is the right place to ask this question, but I am going to ask it anyway.
I have a frequent problem when I try to rename one of my folders; it says access is denied. I have full administrative rights on my computer. The problem occurs only when I try to do it via command prompt or batch files. I can manually rename the folder with no problems whatsoever. But I need to be able to rename it using the ren command. It is an irritating problem, and I have heard other people having the same problems. They usually fix it by re-taking ownership of the folder and restarting the computer. This works for me, but I hate having to do this every time. Is there a permanent solution that I can do to stop this problem? Also, when this problem occurs, it happens to all folders; I can't rename any of them using the ren command.
The answer is quite simple:
Windows does not permit deletion or renaming a directory/folder which is
the current directory of any running process (application/service) like the command process, or
any subdirectory of the directory to rename is the current directory of any running process, or
any file is opened in the directory to rename or any of its subdirectories by any process with OF_SHARE_DENY_READ, OF_SHARE_DENY_WRITE, OF_SHARE_EXCLUSIVE used on opening the file.
In other words as long as the directory itself or any file or subdirectory in this directory or its subdirectories is in use by any application, Windows denies renaming or deleting the directory.
On Unix/Linux it is possible to delete or rename a directory while it is in use by 1 or more running processes. The running *nix process has to handle the special use case that the directory or file just accessed successfully a millisecond before does suddenly not exist anymore.
My approach to solving this problem is to run the utility Handle, by Mark Russinovich of Windows Sysinternals. You can find it here.
This utility will show all the open handles on the system and which process is using them. One of them may have a path to the folder you are trying to rename.
I typically redirect the output of handle.exe to a file.
handle >handles.txt
Then I look at handles.txt in a text editor and search for the name of the folder I was trying to rename. It will appear in a section of handles belonging to the process that is keeping the handle to that folder open, and hence preventing it from being renamed. It shows the pid of the offending process, which you can decide how to deal with, in case you need to terminate it.
e.g. Trying to rename myfolder I forgot I had started a service running using pm2 (a process monitor) The output of Handle.exe included the following:
node.exe pid: 12752 DISCO\Stu
40: File (---) C:\Dev\myfolder\service
I fixed this by disabling Quick Access:
See Screenshot:
[
Well before you can run this command you have to have the privileges to do so as overwriting or modifying files from the command line requires admin rights. Once you got that done, enter the following:
ren (path name) (modified name, no quotation marks)
1 copy path of the folder. To do this, hold shift and right-click, you'll see the "copy as path option"
2 open cmd as admin. To do this, press window + X, then A.
3 in the cmd, type "cd C: then paste the path" so it will be, for example, like:
cd C:\Users\abc\Desktop\music
before you press enter, quote the last name; for example:
cd C:\Users\abc\Desktop\"music"
4 Next, type: ren *.present extension *.new extension; For example, from mp3 to exe:
ren *.mp3 *.exe
If no extension was existing, then, for example:
ren *. *.exe
This should work and eliminate the access denied nuisance.
I solved this problem by giving the user who run the batch full right on the directory. It seems the right from a group membership is not sufficient: the user was member of the local group Administrators and I received a "Access denied". After having added the user account in the directory security with full rights, it does the job.
I am having difficulties with creating a simple batch file.
What I would like is a batch file that will open up a specific directory and copy 2 files from the same directory that the batch file is in and paste them in the directory that was just opened.
So, in this instance, I have a USB flash drive. I have two IE shortcuts that I would like copied and placed in a public desktop.
The .bat file and the 2 files will all be on the root of the flash drive.
So, my understanding is that it should look like this (EWQ is the IE shortcut and keyfinder is just a test file because i wasn't sure on the extensions... i could not figure out what the IE shortcut extension would be as I don't think it has one):
%SystemRoot%\explorer.exe C:\Users\Public\Desktop<br>
copy EWQ C:\Users\Public\Desktop<br>
copy keyfinder.cfg C:\Users\Public\Desktop
I get my public desktop folder to open but nothing copies. I have
tried various prefixes, like "%~dp0\EWQ" (with an without the quotes)
but to no avail.
These will be loaded from a flash drive and I have about 500 to do so I'd like this as quick and possible. Basically, pop in the flash drive, double click the .bat file and yank it out. In theory, it 'should' be the same drive letter every time, but that isn't guaranteed.
Thank you for any help!!!
This is a batch file, let's call it testing.cmd.
#Copy "%~d0\EWQ.url" "%PUBLIC%\Desktop"
#Copy "%~d0\keyfinder.cfg" "%PUBLIC%\Desktop"
Place this file somewhere on your flash drive and double click it, ensuring that both EWQ.url and keyfinder.cfg are in the root of that drive. If you do not have access to the destination you could try by right clicking testing.cmd and choosing Run as administrator.
So I have been searching around for the answer here and am not able to find it. I'm not by any means well-versed with coding these sorts of things so excuse my noobishness.
So I am trying to create a simple batch file for deployment with a backup device for the end user to double-click and copy their profile folder to the backup media.
I am not certain if xcopy or robocopy is the best solution for this, but coming from server administration I am more familiar with robocopy. The copy utility I'm using isn't necessarily the problem, however.
What I have:
robocopy D:\%USERPROFILE% <destination> /e /copyall
While the source resolves to the user profile without issue, I have not been able to derive a variable for the destination that could account for the possibility of different from letters, which I don't think is possible. Is there a variable that sets the destination as the location from where the batch file is launched?
Thank you for the help!
Is there a variable that sets the destination as the location from
where the batch file is launched?
yes, there is:
echo %~dp0
this gives you Drive and Path of your batchfile. For more ~.modifiers see call /?
I have a batch file, and i need to move a folder from one directory to another.
I can do that no problem. But, im hitting a problem after that.
The folder i just moved is created at run time, then moved to the final destination folder where it needs to remain, unless the user decides to delete it.
So, if the user runs the batch file a second time, when it tries to move the run time folder, there is already the old version of the folder at the destination and it gives a "permission denied" error.
So my question is, what is the best way to overwrite the contents of a folder from a batch file?
Right now i am just using the move command. Which works fine for overwriting regular files, but it cannot overwrite folders apparently.
Thanks.
Would suggest to use either xcopy or robocopy for Overwriting folders
Xcopy /E /Y would Overwrite folder ,
please find More options Xcopy /?
Please note that i have mentioned this options only to overwrite and not to move folder.