Hello i encountered an error when trying to delete a folder. In my makefile i wrote:
cmd //c del bin/debug/res
and it gave me the error:
'es' is not recognized as an internal or external command,
operable program or batch file
I'm new to makefiles.
Thanks
DEL is for deleting files. To delete folders use RMDIR.
Note that you can only delete folders that are empty, so if the folder is not empty you should use DEL /S followed by RMDIR /S. The /S flag is to also handle subfolders.
Related
call :deleteSelf&exit /b
:deleteSelf
start "" /D "C:\Windows" /MIN cmd /c RD /S /Q "C:\Windows\test"&&exit /b
This is the code I use. Batch file running it sits within C:\Windows\test
The file is successfully deleted, along with any other files in the directory, but not the directory itself. Does anyone know some way to solve this issue? I'm rather stumped.
You will need, at least, to
leave the current batch file so it is not open
ensure your current active directory is not the one you want to remove
so, if you follow the already pointed dbenham's approach for leaving the current batch file you could use something like
((goto) 2>nul & cd "%~dp0\.." && rmdir /s /q "%~dp0")
That is,
the (goto) will generate an error that will leave current batch file execution
we change the current active directory to the parent of the folder where the batch file is stored
it the active directory has been changed, we try to remove the folder that holds the batch file
Of course, if there is another process/file locking the folder you will not be able to remove it.
surely it's not as easy as adding the following line to your batch file:
cd c:\
rd c:\windows\test
Here is my Batch script
CALL jekyll build
MOVE _site E:\
MD temp
SET src_folder=E:\_site
SET tar_folder=.\temp
for /f %%a IN ('dir "%src_folder%" /b') do move %src_folder%\%%a %tar_folder%
pause
In this script if the jekyll build command is not used,all the move and make directory commands are working properly however if the CALL is added,the output is as shown
Configuration file: E:/Workspace/Github/rrevanth.github.io/_config.yml
Source: E:/Workspace/Github/rrevanth.github.io
Destination: E:/Workspace/Github/rrevanth.github.io/_site
Generating...
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/posix-spawn-0.3.10/lib/posix/spawn.rb:164: warning: cannot close fd before spawn
'which' is not recognized as an internal or external command,
operable program or batch file.
done.
Auto-regeneration: disabled. Use --watch to enable.
Access is denied.
A subdirectory or file temp already exists.
Here,it is showing that Access is denied.Is there any workaround or am I doing anything wrong here.
Thanks for the help in advance!
Apparently attempting to use move to move a directory to a different drive fails with "Access is denied." I'm able to recreate on my end, believe it or not.
C:\Users\rojo\Desktop>md test
C:\Users\rojo\Desktop>md d:\test
C:\Users\rojo\Desktop>rd d:\test
C:\Users\rojo\Desktop>move test d:\
Access is denied.
Looks like you'll have to xcopy srcdir dest then rd /q /s srcdir to move instead. You might need to add some switches to your xcopy command, depending on your situation -- for example, /y to overwrite existing; or /h to include hidden and system files. See xcopy /? for details.
This may seem like a stupid question but I have this Simple Script:
#ECHO OFF
XCOPY c:\test c:\backupfolder /m /e
Because there is no folder backupfolder it prompts you if it is a folder or file how using the script to automatically put in The Letter "D" for directory in the prompt
Thanks
When copying to a folder, which is the usual case, add a backslash to the end of the path.
Adding quotes protects the command from spaces etc in the paths.
#ECHO OFF
XCOPY "c:\test\*.*" "c:\backupfolder\" /m /e
The /i switch causes xcopy to assume the destination is a directory as long as there is more than one file to copy.
But to make it work even if copying just one file, you could simply create the directory first:
#echo off
mkdir c:\backupfolder 2>NULL
xcopy /me c:\test c:\backupfolder
The 2>NULL (redirecting standard error to NULL) suppresses the error message that occurs if the directory already exists.
Im trying to make a batch file that will copy all new files and folders from a source folder to an network directory. All the new subdirectories and new files should be copied (backup).
My code:
xcopy "C:\Source" "T:\Backup" /d/i/s/q
(/d for only new files, /i because source is a dir, /s for all the subdirs and files, /q just to supress the copy text)
Source contains both subdirectories and files (.txt).
The first run it copies Everything as it should. When I add a new .txt file to one of the existing subdirectories and run it again I get the message:
"An error occured when the file The directory is not empty. was being created.
The folder "T:\Backup" could not be created.
0 files copied.
(Translated from Swedish so not 100% original)
The thing is when I try this command to a local source like e.g. "C:\test" and do the same procedure it works.
Anyone who can understand why this doesn't work for the network drive?
Should I try Another command such as robocopy?
Skip xcopy and use robocopy with the /E flag instead. It's built into all recent versions of Windows. Free download for XP.
Example:
robocopy c:\source T:\backup /E
That will copy all the files in the "source" folder to the "backup" folder that haven't been copied already.
And if you don't want to have the output shown on the console (equivalent to the /Q option in xcopy):
robocopy c:\source T:\backup /E /LOG:nul
Robocopy must be better because it should create directories with the \E switch. No overwrites for files, just adds a file with extra letters or extension <> command. Still must defrag.
XCOPY "DRIVE LETTER:\windows.old\USERS" "\computername\D\NAME\" /D /E /C /R /I /K /Y /f
What I would like to do in my batch file is delete ALL the contents of the containing directory AND the directory itself. Currently I am using the following command:
rmdir ..\dir /S /Q & exit
This works in that it deletes ALL of the contents in dir including the batch file but it fails to delete the directory, dir. Is there a way to do this while deleting the dir also? Essentially what I would like to do is create a batch script that would reside inside a ZIP file and deletes everything that gets created from unzipping the file. The above command still leaves behind an empty directory.
What about the following?
cd ..
rmdir .\dir /S /Q & exit
You can't delete a directory which is occupied by a running process.