this works for XP Prof. or better:
@ECHO OFF &SETLOCAL
for /f "skip=1delims=." %%a in ('wmic os get localdatetime') do if not defined DateTime set "DateTime=%%a"
ren file1 "STATUS_%DateTime:~0,4%_%DateTime:~4,2%_%DateTime:~6,2%"
Domanda
I have a batch script that is using variables for rename a file. I'm developer and In my pc the script is working but in the production server with another user perfil, the "rename" doesn't work. I probed with another Administrator users but the script doesnt work either. I think it depends of some configuration in the user perfil, related with my Developer perfil that permit it works but i dont have any idea that what could be.
this is my script
========================================
@echo off
ECHO GET FECHA
set ano=%date:~6,4%
set mes=%date:~3,2%
set dia=%date:~0,2%
echo Renombra file1
rename file1 STATUS_%ano%_%mes%_%dia%
========================================
this is the error
"The syntax of the command is incorrect."
this is the ok execution in my developer pc with my user
========================================
C:\Users\pquiroza\Desktop>renombra
GET FECHA
Renombra file1
C:\Users\pquiroza\Desktop
========================================
this is the wrong execution in the server, with the same program with my user or any other user
========================================
C:\Users\pquiroza\Desktop>renombra
GET FECHA
Renombra file1
The syntax of the command is incorrect.
C:\Users\pquiroza\Desktop
========================================
Soluzione 2
this works for XP Prof. or better:
@ECHO OFF &SETLOCAL
for /f "skip=1delims=." %%a in ('wmic os get localdatetime') do if not defined DateTime set "DateTime=%%a"
ren file1 "STATUS_%DateTime:~0,4%_%DateTime:~4,2%_%DateTime:~6,2%"
Altri suggerimenti
The %date:~..%
stuff is probably locale-dependent, and might return different characters and formats when using different locales.
First thing I'd try quoting the arguments to RENAME, as it expects exactly 2 arguments for source and destination: rename "file1" "STATUS_%ano%_%mes%_%dia%"