Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:33:16+00:00 2026-05-29T23:33:16+00:00

The question is marked as ASP classic but an algorithm solution is ok. I

  • 0

The question is marked as ASP classic but an algorithm solution is ok.

I have the following set of files which are sequentially numbered:

1.jpg, 2.jpg, 3.jpg, 4.jpg … X.jpg

I need a function which will take as input two filenames, the fromFile and toFile parameter, and which needs to rename all needed files in such a way that the from file is moved in the sequence before the toFile and the files in between renumbered.

Examples:

Moving 1.jpg onto 4.jpg should do the following:

  • rename 1.jpg to 1.jpg.temp
  • rename 2.jpg to 1.jpg
  • rename 3.jpg to 2.jpg
  • rename 1.jpg.temp to 3.jpg
  • other files are unaffected by the operation

Moving 4.jpg to 2.jpg should do the following:

  • rename 4.jpg to 4.jpg.tmp
  • rename 3.jpg to 4.jpg
  • rename 2.jpg to 3.jpg
  • rename 1.jpg to 2.jpg
  • rename 4.jpg.tmp to 1.jpg
  • other files are unaffected

As input i have an array of strings containing filenames and the two filenames to/from.

Can you tell me what is the best approach to the file renaming?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:33:19+00:00Added an answer on May 29, 2026 at 11:33 pm

    Here is a brief approach, considering all your files will be named numeric.jpg, you’re going to have to build your own functions though:

    FileExists(Filename)
    RenameFile(OriginalFilename,NewFilename)

    <%
    
    Input1 = Request.Form("file1")
    Input2 = Request.Form("file2")
    
    'gets digits only
    Input1Digit = Left(Input1,Instr(Input1,".")) 
    Input2Digit = Left(Input2,Instr(Input2,".")) 
    
    
    'is file1 less than file2?             
    If Input1Digit < Input2Digit Then    
    
        'loop through the digits frontwards 1 to 5
        For x = Input1Digit to Input2Digit    
    
            'if the first loop?
            If cStr(x) = cStr(Input1Digit) Then 
    
                'see if file exists here
                If FileExists(Input1) Then 
                    FileRename(Input1, Input1 & ".temp") 'Rename the file here [From, To]
                    OriginalFileExists = True
                Else
                    FileRename(Input1, Input1Digit & ".jpg"
                    OriginalFileExists = False
                End If
    
            'if not on the first loop?
            Else        
    
                'did the original file exist '.temp'
                If OriginalFileExists Then 
                    NewFileName = cInt(x) - 1
                Else
                    NewFileName = cInt(x)
                End If    
    
                'rename each file here
                RenameFile(x & ".jpg", NewFileName & ".jpg")
    
            End If    
        Next 
    
    Else
    
    
        'loop through the digits more to less 5 to 1
        For x = Input1Digit to Input2Digit STEP -1    
    
            'if the first loop?
            If cStr(x) = cStr(Input1Digit) Then 
    
                'see if file exists here
                If FileExists(Input1) Then 
                    FileRename(Input1, Input1 & ".temp") 'Rename the file here [From, To]
                    OriginalFileExists = True
                Else
                    FileRename(Input1, Input1Digit & ".jpg"
                    OriginalFileExists = False
                End If
    
            'if not on the first loop?
            Else        
    
                'did the original file exist '.temp'
                If OriginalFileExists Then 
                    NewFileName = cInt(x) + 1
                Else
                    NewFileName = cInt(x)
                End If    
    
                'rename each file here
                RenameFile(x & ".jpg", NewFileName & ".jpg")
    
            End If    
        Next 
    
    
    
    End If
    %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have marked this question as community wiki, so no rep points are thrown
I have an asp:ListView control which list playlists. It has paging supported and holds
My question is as follows: I have a base controller (ASP.Net MVC controller) called
I'm using a framework which uses the MVC paradigm. It's CodeIgniter, but my question
(Note, this question has been marked answered in Debugging Sharepoint timer jobs but I'm
Update 25/03/2011 I've marked this question as answered, while I don't yet have the
This question is marked as a community wiki, and is subjective, but please don't
I have an asp.net application and webservices (asmx) that reside in the same application
This question is a spin-off/evolution of this question . (That question got marked as
We have a ASP.NET MVC with 4-5 different build configurations. Whenever we change the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.