Remove files in given folder but leave files in subfolders [closed] - windows

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I think this should be rather simple but I want to delete all the files that are stated in for example: C:\TEST but I want to leave the files that are located in subdirectories of this folder. For example files in the folder: C:\TEST\Backup should not be deleted.
When using the following batch command all the files get deleted including those located in sub directories but it leaves the folder:
DEL /S C:\TEST\ /q
Does anyone know the command that I need?

It is as simple as this:
from cmdline:
for %a IN (C:\TEST\*.*) do echo "%a"
OR In a batch script, just add an additional %
for %%a IN (C:\TEST\*.*) do echo "%%a"
Just replace echo with del once you are confident with your final script.
OR simply doing:
del C:\TEST /q
All these things can be found by simply opening cmd.exe and running ANY of the commands with the /? switch. For instance.
for /?
del /?
etc.

Related

Problem with Space in Variable on Batch-Script [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have a problem with my batch script.
I want to delete a file witch I first copy in an variable.
If I output the variable all spaces are there.
but if I try to delete it, the filename stops at the first space.
For /F "delims=" %%i in ('dir /B *.mkv') do set orginaldatei=%%~ni.mkv
ECHO %orginaldatei%
del %orginaldatei%
I also tried it without the "delims=".
The solution is to quote the filename.
del "%orginaldatei%"
That's because del accepts a list of files to delete, delimited by spaces.
Quotes help to make clear, if a space is a delimiter or part of a filename.
del my file --- Tries to delete "my" and "file"
del "my file" --- Tries to delete "my file"

xcopy file and folder from a changing directory [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have been having 0 files copied message when attempting to Xcopy files.
Note that I managed to do it successfully by specifying an exact source path as shown below:
xcopy /y %USERPROFILE%\Desktop\WinXTweak\program1.exe %WINDIR%\
xcopy /y %USERPROFILE%\Desktop\WinXTweak\program2.exe %WINDIR%\
xcopy /y %USERPROFILE%\Desktop\WinXTweak\program3.exe %WINDIR%\
Of course, this would only work if the WinXTweak folder is on the desktop. I would like to be able to copy it into a USB drive for instance or any location in my PC and run it. The location of the batch file is inside the WinXTweak folder too. I could not figure out what to do. I tried the ones below but it did fail.
xcopy /y program1.exe %WINDIR%\
xcopy /y program2.exe %WINDIR%\
xcopy /y program3.exe %WINDIR%\
Thanks all in advance,
Thanks all for your reply. After reading more stuff online, I was able to resolve the issue by using the following code. I am a newbie at this, and there might be a much simpler way this is what I used.
#echo off
set source=%~dp0*.exe
set target="%WINDIR%"
xcopy /y "%source%" "%target%"
The suggested answers I will take note and learn so I can use it in the future.
Thank you for helping and best regards,

How do you find the last modified folder in a directory with command prompt? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
In the end, I want to copy the last modified folder in a directory. In order to do this, I need to pass in the name of the last modified folder to xcopy.
How do you find the last modified folder, not file, in a directory with command prompt? I have found many scripts that will find the last modified file, but I cannot seem to find a command that will find the last modified folder.
Any help would be appreciated.
#echo off
for /f "delims=" %%a in (' dir /ad /od /b ') do set "folder=%%a"

Findstr -- exclude a file type -- search only ascii [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I want to run a FINDSTR dos command in a way beyond what it is easily found in "findstr /?". How would I run findstr so that it only searches ascii files. (I am not sure if that is possible. My gut feeling is that it is not possible) Additionally, how would I run this command line so that it would exclude some file times. For example, what if I wanted to exclude .psd files
What is wrong with the /P option that is described in the help?
/P Skip files with non-printable characters.
It worked for me.
To take further control of which files are searched, simply iterate the files with a for loop and add whatever logic you need. To skip .psd files and also skip binary files:
for /f "eol=: delims=" %%F in ('dir /a-d /b^|findstr /live ".psd"') do findstr /p "search" "%%F"
Use a single percent instead of double percents if run from the command line.

how to delete folder in dos console without list all contents deleted? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 13 years ago.
Improve this question
In windowsxp, I use "del /s /q myfolder" to delete a big folder. It will list all files and folders being deleted. is there a way to avoid that long display list?
thanks,
rmdir /s /q myfolder
or rmdir del /s /q myfolder > nul
Which is the equivalent of the Unix/Linux's /dev/null which throws away any outputs as they are redirected to a black hole of a bit bucket...
Edit: Thanks Heinzi for my stoopid error....I have struck out the rmdir and replaced it with del :)
Hope this helps,
Best regards,
Tom.

Resources