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 5 of 10 Topic 2205 of 2236
Post > Topic >>

Re: rename based on file name

by Cesar Rabak <csrabak@[EMAIL PROTECTED] > Mar 26, 2008 at 06:18 PM

Ted Davis escreveu:
> 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. 
> 

Since again we're heading half off topic here...

> 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.

The OP can elide all the AWK contortion using an appropriate port of the 
unix utility date for its OS (which I surmise is a variety of Windows 
due the use of winzip.exe):


C:\>c:\usr\local\wbin\date.exe
Wed Mar 26 18:06:59 BST 2008

C:\>c:\usr\local\wbin\date.exe -d yesterday
Tue Mar 25 18:07:07 BST 2008

C:\>c:\usr\local\wbin\date.exe -d "2 days ago"
Mon Mar 24 18:07:13 BST 2008

These dates can be formated as above:

C:\>c:\usr\local\wbin\date.exe +%Y%m%d
20080326

C:\>c:\usr\local\wbin\date.exe-d yesterday +%Y%m%d
20080325

C:\>c:\usr\local\wbin\date.exe -d "2 days ago" +%Y%m%d
20080324

HTH




 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 22:58:55 CDT 2008.