Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: rename base...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 10 Topic 2205 of 2236
Post > Topic >>

Re: rename based on file name

by Ted Davis <tdavis@[EMAIL PROTECTED] > Mar 26, 2008 at 11:35 AM

On Wed, 26 Mar 2008 05:16:13 -0700, tcdrake wrote:

> I think one option is to have a piece of code which goes through the
> directory and makes a list of all the files. Then use that list to
rename
> the unzipped files based on the list. I just not sure how to implement
it.
> Any ideas?

In your example code, you seem to be trying to rename the same files twice
to different names - that doesn't work.  Also, you should not use getline
that way - it's so much better to pass the file name as an argument and
let awk take care of the file. 

In a batch file:
  for %%A in (*.dbf) do (
	rename code here
	%%~nA is the file's base name without the extesnion
	%%~xA is the extension
	%%~dA is the drive letter and colon
	%%~pA is the directory
  )

The only thing you need awk for is to generate the various date strings. 
Your approach to generating date strings is *way* too complicated - it's
better to use

batch file
  for /f "tokens=1,2" %%A in ('awk "BEGIN{print
 strftime(\"%%Y%%m%%d\",systime()-86400) \" \"
 strftime(\"%%Y%%m%%d\",systime()-2*86400)}"') do ( set yesterday=%%A& set
 daybefore=%%B)

All one line.  Then the two dates are in the named environment variables
in YYYYMMDD format.  I don't see any reason for the daybefore, you your
code generates it.

So your big mess of way too complicated awk code seems to resolve to

  @[EMAIL PROTECTED]
 off
  set base=c:\po\test\users\test\
  for /f "tokens=1,2" %%A in ('awk "BEGIN{print
 strftime(\"%%Y%%m%%d\",systime()-86400) \" \"
 strftime(\"%%Y%%m%%d\",systime()-2*86400)}"') do ( set yesterday=%%A& set
 daybefore=%%B)
  for /f %%A in (stores.txt) do (
  for %%B in ( %base%%%A\*.dbf) do ren %%B %%~nB%yesterday%%%~xB
  )

Using gawk.exe in the Windows XP environment.  Remember that real lines
are indented two spaces, lines indented less than that are wrapped from
the above line.

-- 
T.E.D. (tdavis@[EMAIL PROTECTED]
)




 10 Posts in Topic:
rename based on file name
tcdrake <rymills@[EMAI  2008-03-26 05:16:13 
Re: rename based on file name
Cesar Rabak <csrabak@[  2008-03-26 11:26:44 
Re: rename based on file name
Ed Morton <morton@[EMA  2008-03-26 10:04:06 
Re: rename based on file name
Ted Davis <tdavis@[EMA  2008-03-26 11:35:42 
Re: rename based on file name
Cesar Rabak <csrabak@[  2008-03-26 18:18:11 
Re: rename based on file name
Ted Davis <tdavis@[EMA  2008-03-26 19:10:01 
Re: rename based on file name
tcdrake <rymills@[EMAI  2008-03-28 08:30:29 
Re: rename based on file name
tcdrake <rymills@[EMAI  2008-03-28 10:08:26 
Re: rename based on file name
Ted Davis <tdavis@[EMA  2008-03-28 15:17:02 
Re: rename based on file name
Cesar Rabak <csrabak@[  2008-03-28 20:40:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 23:28:29 CDT 2008.