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

x
?
Solved

File Extension change

Posted on 2012-12-27
14
Medium Priority
?
572 Views
Last Modified: 2012-12-27
This is suppose to be straightforward but it's not, I need to change the file extension using a batch job on files with .txt extension to .bak, what the simplest way.

Thx
0
Comment
Question by:Roberto Madro R.
  • 6
  • 3
  • 3
  • +1
14 Comments
 
LVL 1

Expert Comment

by:Shizzo
ID: 38724449
All .TXT files?
0
 

Author Comment

by:Roberto Madro R.
ID: 38724465
Yes,

And that's my issue, I need to retain the name(s) of the file(s) but only change their extension.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 38724466
At a command prompt you can just do this from that folder:

REN *.TXT *.BAK

~bp
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
LVL 22

Assisted Solution

by:mcsween
mcsween earned 1332 total points
ID: 38724481
I would use vbscript for this.  Save the code below to a .vbs and change "C:\MyFolder\" to the folder you want to work from.

Option Explicit
Dim fso, strFldr, colFiles, objFile

strFldr = "C:\MyFolder\"
Set fso = CreateObject("Scripting.FileSystemObject")

Set colFiles = fso.GetFolder(strFldr).Files

For Each objFile In colFiles
	If Eval ("txt" = fso.GetExtensionName(objFile)) Then
		fso.MoveFile objFile.path, Left(objFile.path,Len(objFile.path) - 3) & "bak"
	End If
Next

Open in new window

0
 

Author Comment

by:Roberto Madro R.
ID: 38724492
NO, "Ren" expects a literal in the second half of the command, "*. etc." works well with Delete, Copy, etc., not with "Ren"
0
 
LVL 1

Expert Comment

by:Shizzo
ID: 38724510
ren *.txt *.bak will work if they are all in one folder.
0
 

Author Comment

by:Roberto Madro R.
ID: 38724511
How do I invoke this?
0
 

Author Comment

by:Roberto Madro R.
ID: 38724550
How do I call up this vbscript?
0
 
LVL 22

Expert Comment

by:mcsween
ID: 38724556
Open Notepad and paste the code in then save it with a .vbs extension.  To call it just double click it.

You can call it from the command line too

cscript.exe C:\Path\To\Script.vbs

Open in new window

0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 38724579
The command I suggested will certainly work fine, here's an example.

C:\Temp\ee>dir
 Volume in drive C is Windows 7
 Volume Serial Number is 0000-0000

 Directory of C:\Temp\ee

12/27/2012  01:17 PM    <DIR>          .
12/27/2012  01:17 PM    <DIR>          ..
12/27/2012  01:17 PM                 2 1.txt
12/27/2012  01:17 PM                 2 2.txt
12/27/2012  01:17 PM                 2 3.txt
               3 File(s)              6 bytes
               2 Dir(s)   4,508,450,816 bytes free

C:\Temp\ee>ren *.txt *.bak

C:\Temp\ee>dir
 Volume in drive C is Windows 7
 Volume Serial Number is 0000-0000

 Directory of C:\Temp\ee

12/27/2012  01:17 PM    <DIR>          .
12/27/2012  01:17 PM    <DIR>          ..
12/27/2012  01:17 PM                 2 1.bak
12/27/2012  01:17 PM                 2 2.bak
12/27/2012  01:17 PM                 2 3.bak
               3 File(s)              6 bytes
               2 Dir(s)   4,508,454,912 bytes free

Open in new window

~bp
0
 

Author Comment

by:Roberto Madro R.
ID: 38724581
Thanks, it worked,

Can I call a .vbs from a batch file (I'm thinking I should be able to), what do you think?

Thx
0
 
LVL 22

Assisted Solution

by:mcsween
mcsween earned 1332 total points
ID: 38724594
sure can just call it like this in your batch file.

cscript.exe C:\Path\To\Script.vbs

Open in new window

0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 668 total points
ID: 38724600
And this will even work at a DOS command line if you don't want to run it from the actual folder:

ren "c:\temp\ee\*.txt" *.bak

I don't understand why you would want to call a VBS script to do this one line DOS command, from a BAT file.  Am I missing something?

~bp
0
 

Author Closing Comment

by:Roberto Madro R.
ID: 38724842
In good hands with EE, Thanks to both of you "mcsween" & "billprew".
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question