Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Batch file for excel purposes not executing correctly.

I have a .bat  file that i need to rename a file to another name.

The file could be anywhere on the pc..


i get an error now on:

for %%a in  (C) do ren "%%a":\Data2013.xlam "%%a":\Current_Data2013.xlam /s /f

not correct syntax ?

Any Help please.

fordraiders
0
Fordraiders
Asked:
Fordraiders
  • 5
  • 4
1 Solution
 
Chris MillardCommented:
I'm on a Mac at the moment, so cannot confirm but I think you need to add a colon ':' after the (C so that it reads:-

for %%a in (C:) do ren "%%a":\Data2013.xlam "%%a":\Current_Data2013.xlam /s /f
0
 
DiscGolfDadCommented:
Leave off the quotation marks (")

for %%a in (C) do ren %%a:\Data2013.xlam %%a:\Current_Data.xlam /s /f
0
 
FordraidersAuthor Commented:
neither suggestion is working...sorry.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
DiscGolfDadCommented:
The syntax I gave you is correct, but I'm not sure why you are using the For %%A in to begin with.  You state you are only changing one file, and by specifying only one parameter (C) it is only processing one file and hence is redundant.  If the command does not work without the for %%a in part then it won't work with it, either.  I am not aware of any parameters (/s /f) to the ren (rename) statement at all.  If you type ren /? it will show you the proper syntax ren.  What the For %%a in is supposed to be used for is something more like this:

for %%a in (c d e f) do if exist %%a:\orgfile.txt ren %%a:\orgfile.txt newfile.txt
0
 
FordraidersAuthor Commented:
ok..i need it to look anywhere on the computer..in any folder.. on C:\
0
 
DiscGolfDadCommented:
I've been writing batch files for 30 years, and I know of nothing that will do that through a command prompt.  You'd probably have to have a custom program to accomplish that.
0
 
FordraidersAuthor Commented:
so u have to specify a folder location explicitaly ?
0
 
DiscGolfDadCommented:
Yes, exactly.  Wildcards can be used in filenames, but not folders.
0
 
FordraidersAuthor Commented:
ok Thanks
0
 
FordraidersAuthor Commented:
Thanks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now