Computer Hope

Microsoft => Microsoft DOS => Topic started by: zscipio on June 01, 2009, 03:52:58 PM

Title: copying and renaming files
Post by: zscipio on June 01, 2009, 03:52:58 PM
There are files of the form

a-hire.txt, a-hire-1.txt,......, a-hire9.txt, a-hire-rpt.txt

I would like to single copy command to copy them to files of the form
a-hire-0601.txt, a-hire-1-0601.txt,......, a-hire9-0601.txt, a-hire-rpt-0601.txt .

 I am just putting the month and day on the end of the file before the .txt.

copy a-hir*.txt a-hir*.0601.txt gives me a-hire.txt.0601.txt

Thanks for any help.

Title: Re: copying and renaming files
Post by: billrich on June 01, 2009, 06:39:54 PM
The following is for one case Only:

Code: [Select]
@echo off
:Today
for /f "Tokens=1-3 delims=/-" %%a in ('date /t') do (
set Month=%%a
set Day=%%b
set Year=%%c
)
set Month=%Month:~4,5%


ren a-hire.txt  a-hire-%Month%%Day%.txt
dir a-hire*.*
del a-hire*.*

REM echo Hello > a-hire.txt
C:\>newname.bat

Output:

 
Quote
Volume in drive C is OS
 

Directory of C:\

06/01/2009  07:34 PM                 8 a-hire-0601.txt
               1 File(s)              8 bytes
               0 Dir(s)  304,370,679,808 bytes free
C:\>
Title: Re: copying and renaming files
Post by: gh0std0g74 on June 01, 2009, 06:41:39 PM
here's a vbscript
Code: [Select]
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFS.GetFolder(strFolder)
mth = Month(Now)
d = Day(Now)
If Len(mth) <2 Then
mth="0"&mth
End If
If Len(d) < 2 Then
d = "0"&d
End If
i=mth&d
For Each strFile In objFolder.Files
strFileName = strFile.Name
If InStr(strFileName,"a-hire") > 0 Then
BaseName = objFS.GetBaseName(strFileName)
Extension = objFS.GetExtensionName(strFileName)
NewName = BaseName & "-" & i & "." & Extension
strFile.Name = NewName
End If

Next