Pad Filename

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

Guest

Pad Filename

Postby Guest » Mon Mar 15, 2004 1:07 pm

Is there a way to dynamically pad a filename with zeros to a certain length? For example, I have the following files in a folder:

123.txt
1234.txt
12345.txt

and I want the to all be 8 digits long like the following:

00000123.txt
00001234.txt
00012345.txt

Is there a way to do this with a filter. I have been trying to do this for the past 3 days and haven't been able to figure it out.
Thanks,
Garren

pb

padding

Postby pb » Tue Mar 16, 2004 5:29 am

i would get the electronic listing of file names from the specified directory.
read the file names (as integers, without the suffix) using a c program
fprintf(fp,"%0.7d",number);
command would fix the file name to append with the needed number of zero's. In this case the total length would be 7 characters long. write it to a file with .bat extension and run it (incase of DOS) with a copy/move/rename command should solve the problem.
Unless you want to use MS Excel and save the 0's as a string instead of a number.

User avatar
DataMystic Support
Site Admin
Posts: 2164
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Postby DataMystic Support » Tue Mar 16, 2004 1:11 pm

Inside a restrict to filename filter, use a right justify filter to force the width, then replace all spaces with zeroes.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

jring
Posts: 18
Joined: Tue Sep 23, 2003 3:13 am

yep..

Postby jring » Fri Mar 26, 2004 6:48 pm

I've done this sort of things with Textpipe via Command line textpipe combo...

Dir "C:\director\of\choice" /b > C:\Dir.txt

The output in the file will be:

123.txt
1234.txt
12345.txt

You can now make a filter that creates a rename batch script which pads the filenames to 8 characters.

assuming your files are in C:\ root

Ren C:\123.txt 00000123.txt /q

J-


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: No registered users and 3 guests