-3

I have 1 file in folder \\myserver\myfolder whose file name has a space like
First Name_20180810.csv. I need a command that will run daily to rename
First Name_{date}.csv to FirstName_{date}.csv.

The date in file name changes daily. For example, today the file name is
First Name_20180812.csv, tomorrow the file name is First Name_20180813.csv.

How can I rename First Name_{date}.csv to be FirstName_{date}.csv in folder \\myserver\myfolder ?

Thank you.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
faujong
  • 949
  • 4
  • 24
  • 40

1 Answers1

2

the ren command can use wildcards, but it acts unexpected:

From First Name_20180812.csv,

ren "first Name_*" FirstName_*

would generate FirstName__20180812.csv. (the length of the wildcard replacing string has the same length)

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: =!"
)
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • @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 '18 at 12:05
  • @Ross Ridge: It's Windows – faujong Aug 13 '18 at 12:05
  • Thank you ! This command works: ren "\\myserver\myfolder\First Name_{askteriks}" First-Name_{asteriks} @Stephan – faujong Aug 13 '18 at 12:46