Computing.Net > Forums > Programming > Batch File Commands (HELP PLZ!)

Batch File Commands (HELP PLZ!)

Reply to Message Icon

Original Message
Name: darkrain777
Date: December 26, 2007 at 12:53:25 Pacific
Subject: Batch File Commands (HELP PLZ!)
OS: XP
CPU/Ram: AMD/ 1 GIG
Model/Manufacturer: ACER
Comment:

I'm need help creating a batch file that will do a few things. First look at some folders in a directory and determine which is the newest modified/created folder. Then in that newest modified/created folder, find the newest modified file. Copy the newest created/modified file and move to another folder. I already created the other part of my batch file which will upload the newest file to the FTP site.


Report Offensive Message For Removal


Response Number 1
Name: darkrain777
Date: December 26, 2007 at 12:58:23 Pacific
Reply: (edit)

Also, when the file is moved to the new folder, it needs to replace the existing file with the newest file so only the newest file remains in that folder. Thanks anyone for help.


Report Offensive Follow Up For Removal

Response Number 2
Name: User123456789
Date: January 3, 2008 at 04:09:45 Pacific
Reply: (edit)

What I've done in the past, is using the DIR functionality of sorting, to get the wanted output. It is far from being nice and clean ... but it works.

dir /ad /b /od

"ad" only shows directories
"b" shows only the directory name
"od" sorts with newest ones, latest

This is an example output:

dir1
dir2
dir3

If you then parse this one to:

set latest=dir1
set latest=dir2
set latest=dir3

then run this as a command file, you will end up with variable "latest" and content "dir3"

This will do the same with only files:

dir /a-d /b /od

Hi there.


Report Offensive Follow Up For Removal

Response Number 3
Name: darkrain777
Date: January 3, 2008 at 09:50:17 Pacific
Reply: (edit)

Oh, thanks a lot. I appreciate it, and I got it to work too!

my code below:

cd D:\PORT\ftp\
for /f %%D in ('dir /od/ad/b') do set newest=%%D
cd D:\PORT\ftp\%newest%
dir *.jpg /o-d /b > newest.lst
set /p latest=< newest.lst
copy "%latest%" "D:\PORT\MRI\T12N.jpg"
del newest.lst
quit

it searches for the newest folder, then the newest file in that folder and then moves it to another folder. Awesome, thanks User123456789 and Mechanix2Go (whose scripts helped too).


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: January 3, 2008 at 10:34:49 Pacific
Reply: (edit)

Instead of this:

"dir *.jpg /o-d /b > newest.lst
set /p latest=< newest.lst"

Use a FOR:

::==
for /f "tokens=* delims= " %%a in ('dir/b/a-d/od *.jpg') do (
set newest=%%a
)



=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch File Commands (HELP PLZ!)

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge