Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Batch Mass-renaming files help needed.


  • Please log in to reply

#1
helpme768

helpme768

    Member

  • Member
  • PipPip
  • 26 posts
Hi I am making a VisualBasic6 application that can show frames right after eachother just like a movie.
Its quite simple, every 0.03333 seconds it shows "frame1.jpg", then after another 0.033333 seconds it shows "frame2.jpg" and on and on...

However the program that I save all my frames with saved them as "frame0001.jpg", "frame0002.jpg" and so on..
I have 300 frames, and I don't feel like manually renaming them all myself.
There MUST be an easier way.

So could anyone provide me with a simple script that basically removes the extra 0's added from the frame files? So "frame0001.jpg" becomes "frame1.jpg" so the program can read them in the order i designed it for.

Thanks.
  • 0

Advertisements


#2
dsenette

dsenette

    Je suis Napoléon!

  • Administrator
  • 26,041 posts
  • MVP
could you just redo the program to use the file name with the 0's in it?
  • 0

#3
helpme768

helpme768

    Member

  • Topic Starter
  • Member
  • PipPip
  • 26 posts
No because it is "Adobe Flash" which I do not have any rights at all to reverse engineer or decompile.
  • 0

#4
elnikoff

elnikoff

    New Member

  • Member
  • Pip
  • 2 posts
Just make a loop in your base folder, and repeat the replacing of "frame0" by "frame" in the name.

As you are using VB6, you can use the FileSystemObject (reference : Microsoft Scripting Runtime) the following way :
Dim oFSO as new FileSystemObject
Dim oFld as Folder, oFile as File

set oFld = oFSO.getFolder(_the_location_of_your_folder)   'This folder has to exists otherwise there will be an error

for each oFile in oFld.Files
   while left(oFile.Name, 6) = "frame0" 
	  oFile.Name = replace(oFile.Name, "frame0", "frame")
   wend
next

I don't have any possibility to test this code right now. Please try this on another location and copy/paste a subset of your frame files before.
  • 0

#5
Hello71

Hello71

    Member

  • Member
  • PipPip
  • 46 posts
Just to make that a little smaller though (not sure if this works or not):

for each dim oFile in new FileSystemObject.getFolder(_the_location_of_your_folder).Files
   while left(oFile.Name, 6) = "frame0"
	  oFile.Name = replace(oFile.Name, "frame0", "frame")
   wend
next

  • 0

#6
PatrickMc

PatrickMc

    New Member

  • Member
  • Pip
  • 3 posts
An alternate script using biterscripting ( http://www.biterscripting.com ) . I am adding lots comments.


# Go to directory where files are located.
cd "C:/somefolder"
# Get a list of files.
var str list; lf -n "frame*" > $list
# We will store the file count in the following variable.
var int count
# Go thru files one by one.
while ($list <> "")
do
	# Get the next file
	var str file; lex "1" $list > $file
	# Increment count.
	set $count = $count + 1
	# New name is "frame"+$count+".jpg" . Rename file.
	system rename ("\""+$file+"\"") ("frame"+makestr(int($count))+".jpg")
done


Patrick
  • 0

#7
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
Stupid me, I misunderstood a part of the post and assumed you wanted to delete files and make difference between extra zero's to the left of the value.
Anyway, I won't remove the post, it might be of some use.



Old Post:
Hi there.
I once had to mass-delete files and made a VBS-script for it.

history::
It was meant to find .rar files names something like this: myfilePartXXXXXXX.rar
It roughly was about 5 million of them.

The reason I used a script was that any visual appearance or dos-reading of that directory made dos or windows crash.
The only way it didn't crash was when I entered the filename in a way I didn't have to view the whole directory.
So directly deleting it with dos did work, as long as I didn't view the directory it was in...
I didn't want to delete 5 million+ files by hand, so I decided to computalize it.

Here's the source (without comment tags for explanation, if you need help, just ask):
Set objFSO = CreateObject("Scripting.FileSystemObject")
x = 0
on error resume next
do until x = 5780350
	If Len(x) = 1 Then
		objFSO.DeleteFile "D:\program files\adfa2.part00000" &x &".rar"
		x = x + 1
	ElseIf Len(x) = 2 Then
		objFSO.DeleteFile "D:\program files\adfa2.part0000" &x &".rar"
		x = x + 1
	ElseIf Len(x) = 3 Then
		objFSO.DeleteFile "D:\program files\adfa2.part000" &x &".rar"
		x = x + 1
	ElseIf Len(x) = 4 Then
		objFSO.DeleteFile "D:\program files\adfa2.part00" &x &".rar"
		x = x + 1
	ElseIf Len(x) = 5 Then
		objFSO.DeleteFile "D:\program files\adfa2.part0" &x &".rar"
		x = x + 1
	End If
	If x = 500 Then
		msgbox "reached 500"
	ElseIf x = 5000 Then
		msgbox "reached 5K"
	ElseIf x = 50000 Then
		msgbox "reached 50K"
	ElseIf x = 100000 Then
		msgbox "reached 100K"
	ElseIf x = 1000000 Then
		msgbox "reached 1M"
	ElseIf x = 5000000 Then
		msgbox "Almost done..."
	End If
loop

msgbox "done"

note, I already removed some extensive parts of this code which were irrelevant, but you can slim down the weird counting I used.
I only used that way because I had to fake some zero's on the left side of X, so that explains why I just added those in the string and made a check to decide which string to use.

Edited by IO-error, 16 November 2009 - 07:04 PM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP