5
I am wanting to rename a file that is found on the Desktop using batch script. The only line that’s going wrong is this:
rename "%userprofile%\Desktop\Lista.xlsb" "%userprofile%\Desktop\Lista - %usuario%.xlsb"
Right after this line, appears:
Command syntax is incorrect.
I researched a lot, both in Portuguese and in English for a solution and found nothing. I went after pages that explained about the Ren/Rename syntax. I used Ren instead of Rename, I removed the quotation marks, I exchanged quotation marks, I tested everything and nothing. Always giving syntax error.
When I enter the folder, I run without telling the command ren
the way %userprofile%\Desktop\
, it performs without error:
cd %userprofile%\Desktop\
rename "Lista.xlsb" "Lista - teste.xlsb"
Does this mean Rename does not work with variables? This is the only solution?
Bulfaitelo, very grateful for the answer! I will test when I return to work next week and return to see if it worked. I only have Mac at home. I could install a VM software, use a Windows ISO, but I prefer to use the work computer. As for %user%, I used this variable because at the beginning of the code I use a set for user input in this variable, putting its name. But maybe not even needed with the %username%, which would be even better. I will test everything and come back to return. Thanks!
– Jones Santiago
@Jonessantiago Vlw good, holiday! has other variables that can be useful in these bat after a look. LINK MS
– Bulfaitelo
It worked! The tip of using %username% was better than asking the user his name and using this variable in the name of the file, since it is less work for the system user to use the file: the less you type, the better. Thank you!
– Jones Santiago