DOS command to remove a space from a file name

Clash Royale CLAN TAG#URR8PPP
DOS command to remove a space from a file name
I have 1 file in folder \myservermyfolder whose file name has a space likeFirst Name_20180810.csv.
I need a command that will run daily to renameFirst Name_date.csv to FirstName_date.csv.
\myservermyfolder
First Name_20180810.csv
First Name_date.csv
FirstName_date.csv
The date in file name changes daily. For example, today the file name isFirst Name_20180812.csv, tomorrow the file name is First Name_20180813.csv.
First Name_20180812.csv
First Name_20180813.csv
How can I rename First Name_date.csv to be FirstName_date.csv in folder \myservermyfolder ?
First Name_date.csv
FirstName_date.csv
\myservermyfolder
Thank you.
dos != cmd :-)– paxdiablo
Aug 13 at 1:59
dos != cmd
DOS only did 8.3 file names.
– Squashman
Aug 13 at 2:13
What operating system are you using?
– Ross Ridge
Aug 13 at 3:06
Windows cmd is not DOS
– phuclv
Aug 13 at 5:10
1 Answer
1
the ren command can use wildcards, but it acts unexpected:
ren
From First Name_20180812.csv,
First Name_20180812.csv
ren "first Name_*" FirstName_*
would generate FirstName__20180812.csv. (the length of the wildcard replacing string has the same length)
FirstName__20180812.csv
That leaves you to two options: either don't remove the space but replace it like:
ren "first Name_*" "First-Name_*"
or use a short script to remove the space (actually: remove all spaces):
@echo off
REM for /l %%i in (4 1 9) do break>"First Name_2018081%%i.csv"
REM (uncomment above line to generate some testfiles)
setlocal enabledelayedexpansion
for %%A in ("first name_*") do (
set "file=%%A"
ren "%%A" "!file: =!"
)
@Aacini: Yes, I need to remove one space placed at any place from a file name and the structure of the file name is always the same. But, there is a date in the file name, so today the file name will be First Name_081318.csv, tomorrow it will be First Name_081418.csv.
– faujong
Aug 13 at 12:05
@Ross Ridge: It's Windows
– faujong
Aug 13 at 12:05
Thank you ! This command works: ren "\myservermyfolderFirst Name_askteriks" First-Name_asteriks @Stephan
– faujong
Aug 13 at 12:46
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
The central point in this question is to remove one space placed at any place from a file name. Is this right? If so, then the structure of the file name is always the same (and don't change daily)...
– Aacini
Aug 13 at 1:55