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"
Related
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.
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 6 years ago.
Improve this question
I'm trying to remove certain characters from multiple files which share the same extension. An example would be: filename = 01songname.mp3 to songname.mp3, but doing that command to all the mp3 files in the directory, not renaming to one name but removing the numbering.
Based on your existing examples this may work for you.
#echo off
FOR %%M IN (*.mp3) DO (
FOR /F "tokens=* delims=0123456789" %%G IN ("%%~M") DO ECHO RENAME "%%~M" "%%~G"
)
pause
Remove the word ECHO before the word RENAME if you feel the output on the screen looks correct.
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"
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.
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
In Dos if you type
copy c:\a.txt
it will copy a.txt* (a.txt1, a.txtb, etc)
how can I just copy a.txt?
Your question is not correct - copy c:\a.txt will only copy the single file to the current directory. It will ignore the other files like a.txt1 and a.txtb.
You must have tried copy c:\*.txt - that will copy all forms because the pattern matching searches both long and short (8.3) names.
You can eliminate the problem by using FINDSTR:
for /f "eol=: delims=" %F in ('dir /b /a-d c:\*.txt^|findstr /eli ".txt"') do #copy "c:\%F"