1.

Solve : Tricky file rename -> using WinXP and Win 2003 server?

Answer»

Hello group.

I've done a quick search for an answer to my problem but could't find one...

I have a file: URNT40.d20061101-t182300
The extension is the date and time, but I would like to either:

1. replace the "." with a "-" and give it a .txt extension
2. add a .txt as an additional extension (URNT40.d20061101-t182300.txt)

I would like to be able to do this WITHIN a batch file if possible.
Thanks for any suggestions.
Regards,
BryanQuote from: BryanRay67 on June 20, 2007, 07:57:13 AM

Hello group.

I've done a quick search for an answer to my problem but could't find one...

I have a file: URNT40.d20061101-t182300
The extension is the date and time, but I would like to either:

1. replace the "." with a "-" and give it a .txt extension
2. add a .txt as an additional extension (URNT40.d20061101-t182300.txt)

I would like to be able to do this within a batch file if possible.
Thanks for any suggestions.
Regards,
Bryan

(2)

for /f "delims=" %%F in ('dir /b') do ren "%%F" "%%F.txt"
Quote from: BryanRay67 on June 20, 2007, 07:57:13 AM

1. replace the "." with a "-" and give it a .txt extension


Code: [Select]Dim theFile
Set objArgs = WScript.Arguments
Set FSO = CreateObject("Scripting.FileSystemObject")
theFile=objArgs(0)
If InStr(1,theFile,".") > 0 Then
Set objFile = FSO.GetFile(theFile)
newString = Replace(theFile,".", "-")
objFile.Move(newString & ".txt")
End If
save as myscript.vbs, type cscript myscript.vbs URNT40.d20061101-t182300 on the command prompt. Works for this file naming format.
Quote
(2)

for /f "delims=" %%F in ('dir /b') do ren "%%F" "%%F.txt"

Thanks for your suggestion. This seems to work with the exception of it ALSO renames my batch file that is in the same folder.
Is there a way to have this batch file in a parent folder and only call the rename for the CONTENTS of a specified CHILD folder?

Thanks!
Bryan
method (1)

This batch file excludes itself from its operation

(thisfile.bat is whatever the batch file is called)

for /f "delims=" %%F in ('dir /b ^| find /v "thisfile.bat"') do ren "%%F" "%%F.txt"

method (2)

place this or the the older batch file in a folder somewhere on your PATH, eg C:\Windows, and call it by name at the command prompt from the directory to be OPERATED upon.


Thanks for your outstanding help!!!!

Regards,
Bryan


Discussion

No Comment Found