Filename without extension in batch script
for %%a in (.*.jpg) do
The code above will store every jpg picture’s name in %%a, but it stores the full name with the file extension, for example “Q.jpg”.
I’m using a cmd utility for resizing images,
resize /width:100 %%a %%a.jpg
It will resize “Q.jpg” and then name it to “Q.jpg.jpg”, as you can see the extension is now a part of file name!!!
I want to avoid it.
How to change extension from en.srt to .srt in command prompt
A simply though clumsy method is to rename the files twice – first remove .srt
, then change .en
to .srt
(given that there are no other files *.en
):
ren "*.en.srt" "*." & ren "*.en" "*.srt"
A more elegant solution is the one provided by user Mofi in his comment:
@for /F "eol=| delims=" %I in ('dir "*.en.srt" /B /A:-D 2^> nul') do @for %J in ("%~nI") do @ren "%~I" "%~nJ%~xI"
In a batch-file this code would look similar to this (note the necessarily doubled %
-signs):
@echo off
rem // Loop through all matching files:
for /F "eol=| delims=" %%I in ('dir "*.en.srt" /B /A:-D 2^> nul') do (
rem /* There are `~`-modifiers for `for` meta-variables that allow to split file names:
rem `~n` returns the base name, so the (last) extension becomes removed;
rem `~x` returns the extension (including the leading `.`);
rem therefore, `%%~nI` is the original file name with `.srt` removed, hence
rem ending with `.en`, and `%%~xI` is the original extension `.srt`;
rem another loop is used to also split off `.en` from `%%~nI`: */
for %%J in ("%%~nI") do (
rem /* Now `%%~J` returned the same as `%%~nI`, but `%%~nJ` removes `.en`;
rem so finally, rename the file to `%%~nJ` plus the original extension `.srt`: */
ren "%%~I" "%%~nJ%%~xI"
)
)
Following the thorough thread How does the Windows RENAME command interpret wildcards? on Super User, I found out that there is a way using a single ren
command:
ren "*.en.srt" "?????????????????????????????????????????.srt"
However, you need to make sure to have enough ?
, namely as many as there are characters in longest matching file name without .en.srt
; otherwise, file names become truncated. You can avoid truncation by replacing the same sequence of ?
instead of *
, so longer file names are not renamed at all:
ren "?????????????????????????????????????????.en.srt" "?????????????????????????????????????????.srt"
Anyway, this only works when the original file names do not contain any more .
besides the two in .en.srt
; otherwise, everything behind the first .
becomes removed and (finally replaced by srt
).
How to change files extension with bat
I need to change files extension in folders and subfolders by creating bat file
Example
File1.txt
File2.txt
………
FileN.txt
Should be renamed to
File1.jpg
File2.jpg
File3.jpg
………
FileN.jpg
inside the folder and in subfolders.
Additionally then
File1.txt
File2.txt
.........
FileN.txt
should be removed
I have tried for /d /r %f in (.) do ren "%f*.txt" "*.jpg"
but it didn’t worked for me
Macos
On macOS, you need to place the data folder as a sibling of the application itself. Since the folder will be alongside the application, you need to name it specifically so that Code can find it. The default folder name is code-portable-data:
|- Visual Studio Code.app |- code-portable-data
Portable mode won’t work if your application is in quarantine, which happens by default if you just downloaded Visual Studio Code. Make sure you remove the quarantine attribute, if portable mode doesn’t seem to work:
xattr -dr com.apple.quarantine Visual Studio Code.app
Note: On Insiders, the folder should be named code-insiders-portable-data.
Why does the assoc command in cmd doesn’t change the program that opens a file with the specified extension?
I have tried a lot, but the assoc command doesn’t work for me.
When I type
assoc .html=txtfile
the command seems to have been executed as expected. When I check the extension and the associations the .html association has changed to txtfile. But normally it should mean, that the .html files are opened with notepad from now, shouldn’t it? Because that is not the case!
I also tried to restart my PC after that.
What have I done wrong?
Windows and linux
After unzipping the Visual Studio Code download, simply create a data folder within Visual Studio Code’s folder:
|- VSCode-win32-x64-1.25.0-insider | |- Code.exe (or code executable) | |- data | |- …
From then on, that folder will be used to contain all Visual Studio Code data, including session state, preferences, extensions, etc.
The data folder can be moved to other Visual Studio Code installations. This is useful for updating your portable Visual Studio Code version: simply move the data folder to a newer extracted version of Visual Studio Code.
Addendum
@BmyGuest asked why a downvoted answer (del /s c:*.blaawbg) was any different than my answer.
There’s a huge difference between running del /S *.jpg and del /S C:*.jpg. The first command is executed from the current location, whereas the second is executed on the whole drive.
In the scenario where you delete jpg files using the second command, some applications might stop working, and you’ll end up losing all your family pictures. This is utterly annoying, but your computer will still be able to run.
However, if you are working on some project, and want to delete all your dll files in myProjectdll, and run the following batch file: