del /s /q "file location" isn't working - batch-file

del /S /Q "C:\TEST\TESTFOLDER\"
isn't actually deleting TESTFOLDER.

Del command is used for deleting files. If you want to delete folder, you should use rmdir with /s /q switches to force delete the folder and all it's files without prompt
rmdir /S /Q "C:\TEST\TESTFOLDER\"

Related

How to Generate Visual Studio Project Files from Unreal Engine .uproject file with a batch file?

I have a batch file as follows to clean my UE project.
del *.sln
rmdir /s /q .vs
rmdir /s /q Binaries
rmdir /s /q Intermediate
rmdir /s /q Saved
rmdir /s /q DerivedDataCache
"C:\Program Files (x86)\Epic Games\Launcher\Engine\Binaries\Win64\UnrealVersionSelector.exe" /projectfiles Attaching.uproject
Unfortunately, when I run the batch, I get an error as follows:
I found the last command in the batch by reverse-engineering as shown below:
Question
What is the correct way to generate Visual Studio project files from a batch file?
After wasting a lot of time, I found the solution. We have to fully qualify the project path.
echo off
del *.sln
rmdir /s /q .vs
rmdir /s /q Binaries
rmdir /s /q Intermediate
rem rmdir /s /q Saved
rmdir /s /q DerivedDataCache
set MyUVS="C:\Program Files (x86)\Epic Games\Launcher\Engine\Binaries\Win64\UnrealVersionSelector.exe"
set MyUBT="f:\Program Files\Epic Games\UE_4.26\Engine\Binaries\DotNET\UnrealBuildTool.exe"
rem change Transformation to your own project name
set MyFullPath="%cd%\Transformation"
%MyUVS% /projectfiles %MyFullPath%.uproject
%MyUBT% Development Win64 -Project=%MyFullPath%.uproject -TargetType=Editor -Progress -NoEngineChanges -NoHotReloadFromIDE
%MyFullPath%.uproject
%MyFullPath%.sln
I hope this answer is also useful for others in the future!

How to delete folder in the folder?

How to delete files and folders in the folder?
Eg. "cat" folder. In the folder existing (3 folders and 5 mp3s and 4 docxs)files.
I delete with this codes:
del /f /s /q c:\cat
rd /s /q c:\cat
del..... it delete mp3, docx but not del 3 folders. It delete files in the 3 folder.it not del 3 folders.
rd...... it delete "cat" folder, I don't del "cat" folder. I want is to delete files and folders in the "cat" folder.
for /d %%a in (c:\cat\*) do echo rd /s /q "%%~a"
Removes (deletes) a directory.
RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path
/S Removes all directories and files in the specified directory
in addition to the directory itself. Used to remove a directory
tree.
/Q Quiet mode, do not ask if ok to remove a directory tree with /S
rd /s /q c:\cat
md c:\cat
(as you don't need no files or folders inside you can delete the folder and re-create it)
Looking for a better way...EDIT:(I think is not possible without listing items)
for /f "delims=" %%a in ('dir /b "c:\cat"') do (
rd /s /q "%~a" >nul 2>&1||del /q /f "%~a" >nul 2>&1
)
( pushd "c:\cat" && rmdir . /s /q ) & popd
Change to the desired directory.
If that do work, then remove current directory. This will delete all inside the current directory, but, as the current directory is in use, it can't be deleted.
Once finished, return to previous directory

Exclude a folder inside temp when executing a del batch file

What do I add to my DEL batch file if I want to exclude a folder inside a folder I want to delete?
I have this code to delete my all the contents of the temp folder
DEL /F /Q C:\temp
Now, I want to exclude a folder named imptfolder inside. This shouldn't be deleted whether it exists or not inside the temp folder. How do I do this?
Here's some batch script code that'll do what you're asking.
for /d %%I in (c:\temp\*) do (
if /i not "%%~nxI" equ "imptfolder" rmdir /q /s "%%~I"
)
del /q c:\temp\*
If you're just entering these commands from the console, use single percents rather than double.
cd /d c:\temp
for /d %I in (*) do #(if /i not "%~I" equ "imptfolder" rmdir /q /s "%~I")
del /q *

Batch file to perform start, run, %TEMP% and delete all

looking for a way to perform the following:
Start > Run > "%TEMP% > Delete everything (skipping any conflicts).
so Far I have
#echo off
start %TEMP%
DEL *.*
I suppose I could use CD to get to the folder, the thing I'm wondering is if there are any instances where it cannot delete an a dialog box comes up, I want to skip these.
Thanks for the help!
Liam
del won't trigger any dialogs or message boxes. You have a few problems, though:
start will just open Explorer which would be useless. You need cd to change the working directory of your batch file (the /D is there so it also works when run from a different drive):
cd /D %temp%
You may want to delete directories as well:
for /d %%D in (*) do rd /s /q "%%D"
You need to skip the question for del and remove read-only files too:
del /f /q *
so you arrive at:
#echo off
cd /D %temp%
for /d %%D in (*) do rd /s /q "%%D"
del /f /q *
The following batch commands are used to delete all your temp, recent and prefetch files on your System.
Save the following code as "Clear.bat" on your local system
*********START CODE************
#ECHO OFF
del /s /f /q %userprofile%\Recent\*.*
del /s /f /q C:\Windows\Prefetch\*.*
del /s /f /q C:\Windows\Temp\*.*
del /s /f /q %USERPROFILE%\appdata\local\temp\*.*
/Below command to Show the folder after deleted files
Explorer %userprofile%\Recent
Explorer C:\Windows\Prefetch
Explorer C:\Windows\Temp
Explorer %USERPROFILE%\appdata\local\temp
*********END CODE************
If you want to remove all the files in the %TEMP% folder you could just do this:
del %TEMP%\*.* /f /s /q
That will remove everything, any file with any extension (*.*) and do the same for all sub-folders (/s), without prompting you for anything (/q), it will just do it, including read only files (/f).
Hope this helps.
#echo off
RD %TEMP%\. /S /Q
::pause
explorer %temp%
This batch can run from anywhere.
RD stands for Remove Directory but this can remove both folders and files which available to delete.
cd C:\Users\%username%\AppData\Local
rmdir /S /Q Temp
del C:\Windows\Prefetch*.* /Q
del C:\Windows\Temp*.* /Q
del C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Recent Items*.* /Q
pause
#echo off
del /s /f /q %windir%\temp\*.*
rd /s /q %windir%\temp
md %windir%\temp
del /s /f /q %windir%\Prefetch\*.*
rd /s /q %windir%\Prefetch
md %windir%\Prefetch
del /s /f /q %windir%\system32\dllcache\*.*
rd /s /q %windir%\system32\dllcache
md %windir%\system32\dllcache
del /s /f /q "%SysteDrive%\Temp"\*.*
rd /s /q "%SysteDrive%\Temp"
md "%SysteDrive%\Temp"
del /s /f /q %temp%\*.*
rd /s /q %temp%
md %temp%
del /s /f /q "%USERPROFILE%\Local Settings\History"\*.*
rd /s /q "%USERPROFILE%\Local Settings\History"
md "%USERPROFILE%\Local Settings\History"
del /s /f /q "%USERPROFILE%\Local Settings\Temporary Internet Files"\*.*
rd /s /q "%USERPROFILE%\Local Settings\Temporary Internet Files"
md "%USERPROFILE%\Local Settings\Temporary Internet Files"
del /s /f /q "%USERPROFILE%\Local Settings\Temp"\*.*
rd /s /q "%USERPROFILE%\Local Settings\Temp"
md "%USERPROFILE%\Local Settings\Temp"
del /s /f /q "%USERPROFILE%\Recent"\*.*
rd /s /q "%USERPROFILE%\Recent"
md "%USERPROFILE%\Recent"
del /s /f /q "%USERPROFILE%\Cookies"\*.*
rd /s /q "%USERPROFILE%\Cookies"
md "%USERPROFILE%\Cookies"
#echo off
del /s /f /q c:\windows\temp\*.*
rd /s /q c:\windows\temp
md c:\windows\temp
del /s /f /q C:\WINDOWS\Prefetch
del /s /f /q %temp%\*.*
rd /s /q %temp%
md %temp%
deltree /y c:\windows\tempor~1
deltree /y c:\windows\temp
deltree /y c:\windows\tmp
deltree /y c:\windows\ff*.tmp
deltree /y c:\windows\history
deltree /y c:\windows\cookies
deltree /y c:\windows\recent
deltree /y c:\windows\spool\printers
del c:\WIN386.SWP
cls
Just use
del /f /q C:\Users\%username%\AppData\Local\temp
And it will work.
Note: It will delete the whole folder however, Windows will remake it as it needs.

Bat file - remove and copy

I want to remove all directory content (subdirectories and files, but not the main directory).
After that I want to copy all content from other directory to that directory.
How could I do this?
This code doesn't work
cd C:\directory1
rmdir /s/q
pause
xcopy C:\directory2\directory22 C:\directory1 /s /e
rmdir needs a directory to delete, so this will work, but you will get an error message:
cd C:\directory1
rmdir . /s /q
pause
xcopy C:\directory2\directory22 C:\directory1 /s /e
But you can also do this:
cd C:\
rmdir C:\directory1 /s /q
md C:\directory1
pause
xcopy C:\directory2\directory22 C:\directory1 /s /e

Resources