DPChallenge: A Digital Photography Contest You are not logged in. (log in or register
 

DPChallenge Forums >> General Discussion >> Help With A DOS Batch Program
Pages:  
Showing posts 1 - 14 of 14, (reverse)
AuthorThread
05/25/2009 11:01:56 AM · #1
I do things the old fashiohed way. I'm trying to write a DOS-type batch (.bat) program that moves all files in folder F:\IMAGES to a subfolder F:\IMAGES\RECYCLE where the following is true: xxxxxxxx.ORF exists in folder X but xxxxxxx.JPG does not.

I'm on Windows XP. Any ideas? Or maybe point me to a good resouce?
05/25/2009 11:46:33 AM · #2
@ECHO OFF
CLS
copy F:\IMAGES\*.ORF F:\IMAGES\RECYCLE
DEL /S F:\IMAGES\*.ORF
exit

Message edited by author 2009-05-25 11:47:18.
05/25/2009 11:52:12 AM · #3
or you can use move rather than copy then delete
ie.
move f:\images\*.orf f:\images\recycle
05/25/2009 11:53:42 AM · #4
I go back as far as DOS 3.1 Unfortunately, my memory only goes back as far as yesterday. I hope David's suggestion works for you. --Rick
05/25/2009 12:00:21 PM · #5
Thanks. This helps, but I'm looking for a conditional move. For instance, I might have a folder directory that looks like this.

a.orf
a.JPG
b.orf
c.orf
d.orf
d.JPG
e.orf
e.JPG

Since b.orf and c.orf have no corresponding .JPG, I only want to move those.
05/25/2009 12:18:37 PM · #6
IF EXIST file ( do something ) ELSE ( do something else )
05/25/2009 12:37:33 PM · #7
The command you are looking for is 'exist', I did something like this ages ago, so I am only throwing out some ideas.

Start with piping the directory into 2 text files.

dir *.jpg /b > jpgs.txt
dir *.orf /b > orfs.txt

This makes a file with a list of all your jpg files, and one with all your .orf files.

Google 'dos textfile parsing' for info on using.


Message edited by author 2009-05-25 12:47:23.
05/25/2009 01:16:44 PM · #8
Not sure I completely understand what you want to do. This command should move xxx.jpg to another folder if there is a xxx.orf file in the same folder.

for %%f in (*.jpg) do if exist %~nf.orf move %f .\recycle

This page is a good reference of DOS commands.
05/25/2009 02:10:47 PM · #9
gys is close, but I think the logic is a bit sideways from what he's asking for. He wants to move file.orf if the corresponding file.jpg does NOT exist.

First, my standard disclaimer. Friends don't let friends write .bat. That's as bad, if not worse than csh. Can I interest you in a nice installation of cygwin, perhaps? ksh (or even sh/bash/etc.) for this is much, much prettier.

I assume when you mention "folder X" that you expect this to act recursively for all files/dirs under the "images" directory, and the test for file existence should only check the *same* directory as the .orf file we are iterating over.

---
@echo off
for /f %%F in ('dir /a:-d /b /s f:\images\*.orf') do call:checkFile %%F
:checkFile
if exist %~1 if not exist %~d1%~p1%~n1.jpg move %~1 f:\images\recycle\
goto:eof
---
05/25/2009 02:49:42 PM · #10
Hardly anyone ever mentions it, but there is a better alternative for scripting in the Windows environment. It's called Powershell, and it is a standard feature in Win7, but also can be installed as an option in Vista and XP (for XP, SP2 must be installed at minimum, and .net 2.0 or later is required.)
What you want to do can, however be accomplished in a DOS batch file. I see that others have already posted better references to the DOS command syntax than I provided, so edited this.

Build a test folder with a few files, and experiment on that folder. Keep a copy of the folder elsewhere so you can restore it if your batch file does something unexpected. I'm always *very* careful about using batch files that move or delete files, especially when using wildcards.

Message edited by author 2009-05-25 14:52:11.
05/25/2009 10:08:34 PM · #11
"Exist" is what I was looking for. This gives me enough to get started. Thanks also for the helpful link and starter scripts. I'll break the DOS habit one day...
05/25/2009 11:02:57 PM · #12
I'll second cygwin, and/or a "real" scripting language like perl, python, etc. By real, I guess I mean portable - you might be able to use it again whether in Windows, Linux, or on a Mac.
05/26/2009 12:31:41 AM · #13
Originally posted by cdrice:


---
@echo off
for /f %%F in ('dir /a:-d /b /s f:\images\*.orf') do call:checkFile %%F
:checkFile
if exist %~1 if not exist %~d1%~p1%~n1.jpg move %~1 f:\images\recycle\
goto:eof
---


OMG, a GOTO, an actual GOTO! Someone should photograph this for unusual objects ;-)
07/30/2009 12:46:03 PM · #14
I'm looking for a conditional move ( from F:\IMAGES to a subfolder F:\IMAGES\RECYCLE ). For instance, I might have a folder directory that looks like this.

a.orf
a.JPG
b.orf
c.orf
d.orf
d.JPG
e.orf
e.JPG

Since b.orf and c.orf have no corresponding .JPG, I only want to move those.


bvy:

Here is a script.

# Script condmove.bat
# Collect a list *.ORF files in "F:\IMAGES".
var str list ; lf -n "*.ORF" "F:\IMAGES" > $list
# Process files one by one.
while ($list <> "")
do
# Get the next file from the list.
var str orffile ; lex "1" $list > $orffile
# The file name ends in .ORF.
# Create a corresponding name .JPG.
var str jpgfile
sal -c -p "^.ORF^l" ".JPG" $orffile > $jpgfile
# Does the jpf file exist ?
af $jpgfile > null
if ( NOT ($fexists) )
# Corresponding .JPG file does not exist. Move.
system move $orffile "F:\IMAGES\RECYCLE"
endif
done

The script is in biterscripting (I added enough comments so you can translate it into batch or another language.) To run, save the script as C:\Scripts\condmove.bat, start biterscripting, enter the following command.

script condmove.bat

Richard
Pages:  
Current Server Time: 04/25/2024 03:35:55 AM

Please log in or register to post to the forums.


Home - Challenges - Community - League - Photos - Cameras - Lenses - Learn - Prints! - Help - Terms of Use - Privacy - Top ^
DPChallenge, and website content and design, Copyright © 2001-2024 Challenging Technologies, LLC.
All digital photo copyrights belong to the photographers and may not be used without permission.
Current Server Time: 04/25/2024 03:35:55 AM EDT.