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 7682693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:37:35+00:00 2026-05-31T18:37:35+00:00

Hi I have recently made this script to rename files I scan for work

  • 0

Hi I have recently made this script to rename files I scan for work with a prefix and a date. It works pretty well however it would be great if it could make a directory in the current directory with the same name as the first file then move all the scanned files there. E.g. First file is renamed to ‘Scanned As At 22-03-2012 0’ then a directory called ‘Scanned As At 22-03-2012 0’ (Path being M:\Claire\Scanned As At 22-03-2012 0) is made and that file is placed in there.

I’m having a hard time figuring out the best way to do this. Thanks in advance!

import os
import datetime
#target = input( 'Enter full directory path: ')
#prefix = input( 'Enter prefix: ')
target = 'M://Claire//'
prefix = 'Scanned As At '
os.chdir(target)
allfiles = os.listdir(target)
count = 0
for filename in allfiles:
    t = os.path.getmtime(filename)
    v = datetime.datetime.fromtimestamp(t)
    x = v.strftime( ' %d-%m-%Y')
    os.rename(filename, prefix + x + " "+str(count) +".pdf")
    count +=1
  • 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-31T18:37:36+00:00Added an answer on May 31, 2026 at 6:37 pm

    Not quite clear about your requirement. If not rename the file, only put it under the directory, then you can use the following codes (only the for-loop of your example):

    for filename in allfiles:
        if not os.isfile(filename): continue
        t = os.path.getmtime(filename)
        v = datetime.datetime.fromtimestamp(t)
        x = v.strftime( ' %d-%m-%Y')
        dirname = prefix + x + " " + str(count)
        target = os.path.join(dirname, filename)
        os.renames(filename, target)
        count +=1
    

    You can check help(os.renames).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently reinstalled MacOSX, and at some point (without realizing it) I made
Recently I have discovered that my release executable (made with msvc++ express 2008) becomes
I recently made the change from Dreamweaver to NetBeans and noticed this IDE doesn't
I have discovered recently that's possible to call anoymous blocks from jdbc like this:
For a site i made, http://crystalmurray.com , i have a simple little script to
I have recently made a horizontal and vertical scrolling site using jquery.scrollTo On the
I have recently made a cp clone (for University) and I happened to discover
I have recently made the transition from a Java web developer to a C#
Alright so I have recently made the decision to put every string in my
i have recently come to this error , i search a lot but i

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.