Solved

Rename a file

Posted on 2006-11-15
9
234 Views
Last Modified: 2010-04-16
Hi there,

I 'am looking for a simple way to rename a file.
In rename.cmd I have this: ren *.* SBS.*
Original file:
231-333.jpg
The result:
SBS-333.jpg
I lost 3 characters.
Is it possible with a cmd to prevent this from happening.

Erik

0
Comment
Question by:fmew
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 17945884
What are you using?  C++, C# etc?  If you can let me know I might be able to help
0
 

Author Comment

by:fmew
ID: 17945973
WOW, Angus Young, my hero!

Well, Iam not a programmer, although I know some basic VB (it should be possible with VB, but I cannot do this).
At the moment I use a query in MsAccess to append characters to a filename, this works.
So the rename function in DOS will not work with this?

Erik
0
 
LVL 9

Expert Comment

by:DjDezmond
ID: 17946011
Its a batch he's using... Dont know why you getting that result though Erik.

Try using a vbscript...
--------------------------------------------------------------------------
Set FSO = CreateObject("Scripting.FilesystemObject")
Set oShell = CreateObject("Wscript.Shell")
Set objShell = CreateObject("Shell.Application")

Set objFolder = FSO.GetFolder("C:\Test")

For Each objFile in objFolder.Files
      FSO.MoveFile objFile, objFolder.Path & "\SBS" & FSO.GetFileName(ObjFile)
Next
--------------------------------------------------------------------------

This script will put 'SBS' on the beggining of every filename... You can change this by altering the following line:

FSO.MoveFile objFile, objFolder.Path & "\SBS" & FSO.GetFileName(ObjFile)

If you need to change it in anyother way and are not familiar with scripting... let us know and we can help you further
0
 
LVL 19

Expert Comment

by:Limbeck
ID: 17946057
ren * sbs*  

should work, tested it
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 9

Expert Comment

by:DjDezmond
ID: 17946059
Ive altered the 'For Each' loop to make it abit clearer on how to change the text string...

For Each objFile in objFolder.Files
      Filename = FSO.GetFileName(ObjFile)                       '-Filename string
      FileWoutExt = Left(Filename, Len(Filename) - 4)        '-Filename without extension
      Extension = FSO.GetExtensionName(ObjFile)              '-Extension
      
<<Put one of the following lines here>>
Next

If the original file is called "1234.Doc" then these lines would change them to:
  FSO.MoveFile objFile, objFolder.Path & "\SBS" & Filename   = SBS1234.Doc
  FSO.MoveFile objFile, objFolder.Path & FileWoutExt & "\SBS" & Extension  = 1234SBS.Doc

This will happen for all files in the directory you specify here:
  Set objFolder = FSO.GetFolder("C:\Test")

Hope this helps...
0
 
LVL 19

Expert Comment

by:Limbeck
ID: 17946121
ah err didnt test it properly, it didnt work. this does

on the commandline:

for %f in (*.*)  do ren %f SBS%f
0
 

Author Comment

by:fmew
ID: 17947009
Limbeck,

This works from the commandline, but not in a batchfile.
Do I do something wrong? Or does it just dont work in a batch!
In <rename.cmd> I have:
cd\
cd C:\Test
for %f in (*.*)  do ren %f S%f

DjDezmond,
I try the VBscript later

Erik
0
 
LVL 19

Accepted Solution

by:
Limbeck earned 250 total points
ID: 17947060
for a batch fileuse %%f instead of %f

for %%f in (*.*)  do ren %%f S%%f
0
 

Author Comment

by:fmew
ID: 17969600
the vb code is probebly ok, but I was looking for a dos batch code, so i'll  grade limbeck, course this works. I hope you agree DjDezmond!
(just for fun)! where is my hero angus, my 6 year old boy is fond about you. Playbacking you with his gitar.  

Thank you all

Erik
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
maxMirror challenge 10 89
pairs challenge 5 44
Tviruailstringtree sort multi columns on header click 1 32
Birthdays 3 0
This article will show, step by step, how to integrate R code into a R Sweave document
This is an explanation of a simple data model to help parse a JSON feed
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now