How to have batch file code only copy the most recent .bak file from a directory

I recently had very kind assistance on how to make the below code copy the most recent file from a file on my C:\ called 'C:! BATCH'

It's transpired that I now need to have the batch file only look for .bak files in this dorectory, and while I'm positive this is a relatively simple tweak, I've so far had no luck on finding how this is done.

Any advice on this would be very much appreciated, many thanks!

@echo off pushd C:\! BATCH setLocal EnableDelayedExpansion for /f "tokens=* delims= " %%G in ('dir/b/od') do (set newest=%%G) copy "!newest!" C:\DROP\ PAUSE

-------------Problems Reply------------

I now need to have the batch file only look for .bak files in this directory.

The change is simply adding *.bak to the dir command.

@echo off

pushd c:\BATCH\

setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%G in ('dir/b/od *.bak') do (set newest=%%G)

copy "!newest!" c:\DROP\look for .bak files in this dorectory

Category:file Views:1 Time:2010-06-24

Related post

  • How can I specify a file to be copied in an Android.mk file 2011-11-18

    Is there a macro or command to copy files? I'd like a 3rd party library (libThirdParty.so) to be copied to the output directory (lib). This is the contents of my Android.mk file LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := ndkFoo

  • Shortest DOS batch file code to get first line of a file set to a variable? 2011-02-16

    I am looking for the shortest amount of DOS code possible that will get the first line of a text file and set it to a variable in DOS/Windows. There are lots of examples of this kind of thing in other threads on this StackExchange site but I am not l

  • copy contents of vector into file 2011-10-14

    i have following code for copying content of vector into file #include<iterator> #include<algorithm> #include<fstream> #include<iostream> #include<vector> using namespace std; void dump(vector<int>& v){ ofstrea

  • W2K Bak file not accepted by XPPro or W2K restore. 2012-10-07

    Prior to a clean install of XPP from W2K backed up entire computer into 2 files of same size with the extensions BAK and CDF. They were backedup on Aux drive D. This was done by the W2K backup wizard. The restore wizard in XP keeps asking for BKF fil

  • Gregory K. Maxey's Recently Used Files Edit addin 2015-03-05

    I recently had Graham Mayor recommend to me Gregory K. Maxey's Recently Used Files Edit addin. I went to Mr. Maxey's webpage, downloaded the Recently Used Files Edit, and extracted it from the WinRAR folder. Unfortunately, while the addin does work f

  • EXCEL.exe & WINWORD.exe supports for a file which contains wide char ( like chinese ) and file name is in chinese 2012-07-14

    Hi, I see the difference in behavior for EXCEL.exe & WINWORD.exe. I have two files ( .xlsx & .docx types) which contain Chinese characters and file name also contain Chinese characters. When I try to open the Chinese ".xlsx" file using EXCEL.

  • How do I get my Recently Changed File back? 2014-02-01

    My friend accidentally deleted my Recently Changed File. I tried retrieving it from the recycling bin by restoring the items in the recycle bin, but it was gone. I tried system restore but it was still not there. I could not try file restore because

  • How to restore folders/messages in Outlook Express from .bak files 2014-08-23

    While cleaning up my desktop, some folders in OE 6 (Win XP) went missing. Looked in OE Store and the .dbx files for the folders weren't there. I found the .bak files for the missing folders in the Recycle bin and moved them to another folder for safe

  • How do I retrieve bak files ? 2013-05-20

    Original Title: Bak files. How do I retrieve bak files. They were email messages that somehow went in the recycle bin. I have retrieved the files but they have bak next to them. Nothing I do will open them. Thanks --------------Solutions-------------

  • Restoring a .bak file on a Win 7 machine 2014-02-25

    I backed up my files from my old XP box to .bak files using the XP backup tool. I am now trying to restore those files in Win 7, but it would appear that MS has once again left those of us using the old backup system out to dry. Does anyone have any

  • How to code a batch file to copy and rename the most recently dated file? 2010-06-17

    I'm trying to code a batch file to copy only the most recently dated file in a given folder to another directory on the local machine, and simultaneously rename it as it does. I've found a very similar question here http://stackoverflow.com/questions

  • What does this batch file code do? 2009-09-25

    What does this bat code do? for /f %%i in ('dir /b Client\Javascript\*_min.js') do ( set n=%%~ni set t=!n:~0,-4! cp Client\Javascript\%%i build\Client\Javascript\!t!.js ) What does %%~ni,~n:~0,-4!,%%i,!t! mean? --------------Solutions------------- Ke

  • Batch file - code to edit a string between strings in a dtsconfig / xml file 2011-03-14

    I have written a batch file to replace certain strings in a dtsConfig file. Now from what I can gather, batch cannot directly edit dtsconfig files so a workaround I'm using which works is to convert the .dtsConfig files into .xml first, edit them, an

  • Need batch file code to replace filepath with cd-rom drive letter 2010-06-08

    Here is the copy statement I have currently. I am looking to replace the F: with %cdrom% so that this script will work no matter what computer it is used on. XCOPY F:\*.* .\disk2\ /C /S /D /Y /I --------------Solutions------------- I just pieced toge

  • batch file to copy a folder containing the most recently created file 2011-02-07

    Hey guys, I'm looking for a batch file which will copy a folder and all its contents containing the most recently created file. I need it to preserve the folder name at the destination aswell. For example: If 'c:\test\source\inhere' contains the most

  • What is the VBA Macro Code to Copy Header and Footer from Template file into Multiple Word Documents at one time? 2014-03-28

    What is the VBA macro code to copy header and footer from template file into multiple word documents at one time? Example: I receive a .doc file that has header and footer within. This header and footer needs applied to multiple files within the same

  • Macro code to copy files in a dir to another 2014-11-04

    I tried to record this macro but all of it did not record. Is it possible to write the code to use windows while in Excel to copy files. I want to be able to run a macro to: copy all files in "C:\My Documents\Files" to "F:\" also assume that the file

  • Batch file to copy last line of several files into one new file 2011-05-10

    I have a load of logs being generated each time an app runs, I want the very last line of each to be collated into a file or printed on screen by a batch file. e.g I have a dir with files like log123.log,log124.log,log125.log --------------Solutions-

  • Unix code wanted to copy template file and replace strings in template file in the copied files 2012-03-28

    I have 2 files: File_1.txt: John Mary Harry Bill File_2.txt: My name is ID, and I am on line NR of file 1. I want to create four files that look like this: Output_file_1.txt: My name is John, and I am on line 1 of file 1. Output_file_2.txt: My name i

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.213 (s). 11 q(s)