DOS CMDs - For and Forfiles to rename files


  1. Posts : 51
    W 10 Pro, W 7 Pro & XP Pro.
       #1

    DOS CMDs - For and Forfiles to rename files


    I have just bought a Surface 4 Pro with k'brd. I find that one old program will no longer run correctly, so need to make a Batch file to replace it.

    Windows 10 screen capture produces files all with the same name, appending a serial number.

    Capture.exe produces a .bmp file with the date/time in the file name. I wish to do this.

    I've investigated the FOR and FORFILES CMDs, but so far no success.

    This code will get the system date:-

    :: Get the date/time
    FOR /f %%a in ('WMIC OS GETLocalDateTime ^| find "."') DO Set _DTS=%%a
    Set _datetime=%_DTS:~0,4%-%_DTS:~4,2%-%_DTS:~6,2%@%_DTS:~8,2%-%_DTS:~10,2%-%_DTS:~12,2%

    Echo Year-MM-Day@HR-Min-Sec
    Echo %_datetime%



    This code with FORFILES will get the file's parameters:-


    @file – Name of the file(includes extension)
    @fname – Name of the file excluding extension @Ext – Extension of the file

    @fdate – Last modified date of the file
    @ftime – Last modified time of the file

    However I can't get them to work together.

    W 10 stores screen dumps (<Win> + <PrtScn>) in a folder, 'Screenshots', under 'C:\Users\myname\Pictures\'.

    A file could be: 'Screenshot (5).png with a UK date of 18/01/2017 21:33

    I want to rename this file:- 'Cap_170118_213315.png'. I've included the seconds, as this is very important and used a 2 digit year as YYMMDD_HHMMss.

    Any suggestings would be most welcome.
      My Computer


  2. Posts : 17,661
    Windows 10 Pro
       #2

    Landyman said:
    Any suggestings would be most welcome.[/FONT][/FONT][/COLOR]
    My suggestion:

    I am normally one of those users who always ask why use a third party solution if Windows native tools can do the same job, but in this case I wholeheartedly recommend using Screenpresso, the best third party screenshot tool I have used.

    It names the screenshots almost as you'd prefer, naming them YYYY-MM-DD_HHhMM_SS.png (that red h is a letter h Screenpresso puts between HH and MM):

    DOS CMDs - For and Forfiles to rename files-image.png

    It let's you freely modify keyboard shortcuts:

    DOS CMDs - For and Forfiles to rename files-image.png

    The free version has some limitations but in all honesty I have not even noticed what the limitations are; all screenshots (and annotations in screenshots) in all my posts and tutorials are made with free version of Screenpresso. Here's a sample, a recent tutorial with several screenshots, annotated and clean: UUP to ISO - Create Bootable ISO from Windows 10 Build Upgrade Files

    (Filenames shown in my screenshots are not actual filenames created by Screenpresso because I use WYSIWYG editor when posting here, pasting screenshots directly in post from clipboard without uploading them first. This makes them all use a default name image.png when you check them here.)

    Download: Download | Screenpresso

    Kari
      My Computer


  3. Posts : 51
    W 10 Pro, W 7 Pro & XP Pro.
    Thread Starter
       #3

    Many thanks Kari. I've downloaded the program and it's user manual. A quick reading session indicates it will solve my problem and do much more.
      My Computer


  4. Posts : 17,661
    Windows 10 Pro
       #4

    You are welcome.

    As I said, I belong to those users who do not see a point in using third party solutions when Windows does it well with its native tools, but in case of screenshots I gave up: Screenpresso is a fabulous tool!
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 14:32.
Find Us




Windows 10 Forums