Author Topic: DOS / Windows Q  (Read 2816 times)

Mr Larrington

  • A bit ov a lyv wyr by slof standirds
  • Custard Wallah
    • Mr Larrington's Automatic Diary
DOS / Windows Q
« on: 04 July, 2008, 12:49:36 pm »
OK, I have two directories:

K:\foo contains the input files
k:\bar contains the output files

Both sets of files have the same names, i.e if file '01 abcdef and a half.xxx' has gone through OK, there will be a '01 abcdef and a half.xxx' in both foo and bar.

Now, some of the input files haven't been processed properly, so directory bar contains only the ones which have.  What I want to do is get a list of all the files in bar, and delete each of its namesakes from foo, so that only the unprocessed files remain.  This seems like it ought to work with the DOS "if EXIST filename DEL filename" wossname, but it seems that the long Windows-stylee filenames are throwing it off the scent.  Can Thee Panel think of a simple way of doing this, preferably without installing some variety of executable line noise scripting language?

I don't have the option of moving kit and kaboodle onto a box with a sensible operating system either chiz as I'd be able to do the thing in three seconds flat >:(
External Transparent Wall Inspection Operative & Mayor of Mortagne-au-Perche
Satisfying the Bloodlust of the Masses in Peacetime

tiermat

  • According to Jane, I'm a Unisex SpaceAdmin
Re: DOS / Windows Q
« Reply #1 on: 04 July, 2008, 12:51:11 pm »
The only way I can think of is to learn Kixtart...

Otherwise DOS was never designed to be a scriptable shell, like CSH, KSH etc etc so you will be SOL....
I feel like Captain Kirk, on a brand new planet every day, a little like King Kong on top of the Empire State

Woofage

  • Tofu-eating Wokerati
  • Ain't no hooves on my bike.
Re: DOS / Windows Q
« Reply #2 on: 04 July, 2008, 12:53:05 pm »
it seems that the long Windows-stylee filenames are throwing it off the scent

Put quote marks around the filenames.
Pen Pusher

Re: DOS / Windows Q
« Reply #3 on: 04 July, 2008, 12:58:56 pm »
OK, first stab:-

If k:\bar doesn't have any subdirectories (otherwise you'll have to trim the list of files):-

dir /b /s k:\bar > k:\del.bat
Use Notepad to search and replace all occurrences of "K:\bar\" with "del "
cd K:\foo
K:\del.bat

but this'll have problems with files with spaces in their names...
"Yes please" said Squirrel "biscuits are our favourite things."

Re: DOS / Windows Q
« Reply #4 on: 04 July, 2008, 01:00:06 pm »
it seems that the long Windows-stylee filenames are throwing it off the scent

Put quote marks around the filenames.

dir /X will print the filenames out in 8.3 format, but you can't use this at the same time as /B
"Yes please" said Squirrel "biscuits are our favourite things."

Re: DOS / Windows Q
« Reply #5 on: 04 July, 2008, 01:00:55 pm »
Code: [Select]
for /f "tokens=*" %a in ('dir k:\bar /b') do del "k:\foo\%a"


You could put it in a batch file if you wanted, but then replace % with %%

Code: [Select]
for /f "tokens=*" %%a in ('dir k:\bar /b') do del "k:\foo\%%a"


Sorry for the delay in replying...  I was just testing it out :)

Re: DOS / Windows Q
« Reply #6 on: 04 July, 2008, 01:07:28 pm »
I know you don't want to but I would install Cygwin then you would have a bash shell tor work with and even perl if that was easier for you.
I think you'll find it's a bit more complicated than that.

Re: DOS / Windows Q
« Reply #7 on: 04 July, 2008, 01:11:47 pm »
I'm sure the one line of code I posted is easier than installing software, or listing stuff out in text files for manual editing ;)

Re: DOS / Windows Q
« Reply #8 on: 04 July, 2008, 01:13:44 pm »
Thank you nutty, I'm sure that'll come in useful...

If your param is called %a you could use %~sna without the need for double quotes.

The s modifier makes it only print out the short 8.3 name and the n modifier makes it only print out the filename (the s modifier reverts the output to the full path).

(Although, thinking about it, there's no guarantee that the 8.3 name will be the same for two files with the same long names.)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: DOS / Windows Q
« Reply #9 on: 04 July, 2008, 01:16:49 pm »
I'm sure the one line of code I posted is easier than installing software, or listing stuff out in text files for manual editing ;)

That's why I like learning new stuff like this.

I don't bother setting up a comfortable environment with PERL, bash/tcsh/zsh, python, or whatever else needs to be installed because I often have to do my work on machines that have none of these programs installed.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: DOS / Windows Q
« Reply #10 on: 04 July, 2008, 01:18:47 pm »

If your param is called %a you could use %~sna without the need for double quotes.


Could well do, but I stick to the kiss principle, "Keep it simple, stupid".  By putting the quotes in you can ensure that it uses the long name on the disc, instead of the shortened one.  I have had problems in the past when file~1.txt is not the same as file~1.txt created in a different directory.

Re: DOS / Windows Q
« Reply #11 on: 04 July, 2008, 01:23:55 pm »
I'm sure the one line of code I posted is easier than installing software, or listing stuff out in text files for manual editing ;)

That's why I like learning new stuff like this.

I don't bother setting up a comfortable environment with PERL, bash/tcsh/zsh, python, or whatever else needs to be installed because I often have to do my work on machines that have none of these programs installed.

You can run Cygwin from a USB stick


I think you'll find it's a bit more complicated than that.

Mr Larrington

  • A bit ov a lyv wyr by slof standirds
  • Custard Wallah
    • Mr Larrington's Automatic Diary
Re: DOS / Windows Q
« Reply #12 on: 04 July, 2008, 01:38:27 pm »
Code: [Select]
for /f "tokens=*" %a in ('dir k:\bar /b') do del "k:\foo\%a"

We have a winner!  Have a :thumbsup:
External Transparent Wall Inspection Operative & Mayor of Mortagne-au-Perche
Satisfying the Bloodlust of the Masses in Peacetime

Re: DOS / Windows Q
« Reply #13 on: 04 July, 2008, 01:43:59 pm »
Ta  :thumbsup:



Re: DOS / Windows Q
« Reply #14 on: 04 July, 2008, 01:48:00 pm »
I'm sure the one line of code I posted is easier than installing software, or listing stuff out in text files for manual editing ;)

That's why I like learning new stuff like this.

I don't bother setting up a comfortable environment with PERL, bash/tcsh/zsh, python, or whatever else needs to be installed because I often have to do my work on machines that have none of these programs installed.

You can run Cygwin from a USB stick

1. Requires physical access to the computer
2. Against security policy to plug in a USB stick to the computer
3. Against IT security policy to run any unauthorised/unvetted software
4. (Depending on circumstances) Against security policy to be in possession of a USB stick

Fine for fixing stuff on your home machine or dev scratch boxes but corporate environments are often much more restrictive.
"Yes please" said Squirrel "biscuits are our favourite things."

tiermat

  • According to Jane, I'm a Unisex SpaceAdmin
Re: DOS / Windows Q
« Reply #15 on: 04 July, 2008, 01:49:00 pm »
I'm sure the one line of code I posted is easier than installing software, or listing stuff out in text files for manual editing ;)

That's why I like learning new stuff like this.

I don't bother setting up a comfortable environment with PERL, bash/tcsh/zsh, python, or whatever else needs to be installed because I often have to do my work on machines that have none of these programs installed.

You can run Cygwin from a USB stick

1. Requires physical access to the computer
2. Against security policy to plug in a USB stick to the computer
3. Against IT security policy to run any unauthorised/unvetted software
4. (Depending on circumstances) Against security policy to be in possession of a USB stick

Fine for fixing stuff on your home machine or dev scratch boxes but corporate environments are often much more restrictive.

You forgot 5, in some locations if you take a usb stick in, it ain't ever coming out again.....
I feel like Captain Kirk, on a brand new planet every day, a little like King Kong on top of the Empire State

Re: DOS / Windows Q
« Reply #16 on: 04 July, 2008, 01:50:42 pm »
and 6.   USB stick may not be readable by the computer if security policy is for encrypted/specific sticks only permitted to be used.

Re: DOS / Windows Q
« Reply #17 on: 04 July, 2008, 02:02:07 pm »
Reminds me of a couple of interview questions we used for people who said they "knew UNIX".

Two files (A.txt and B.txt) contain a bunch of strings one per line. Nothing tricky. No duplicates within each file. All 7-bit clean ASCII.

So they could look like this:-

$ cat A.txt
foo
dog
badger
mushroom mushroom!
$

but they could be hundreds of thousands of lines long.

1) How would you find out which entries are listed in only one of the files (either A.txt or B.txt but not both)?

2) How would you find out which entries are listed in file A.txt and not in B.txt?

It's amazing how many people launch into a speech on writing some PERL/Python/etc to read them into a hash (or two hashes) and then fiddle around with stuff. Blah blah blah.

After they've detailed their design, it's countered with "What if PERL/Python/etc isn't installed?"

Repeat this with whatever they pick next that isn't on a standard OS install and keep doing this until you get one of two answers:

a) Don't know. Bzzzt. Thanks for playing.
b) See spoiler for what we hoped would be their first answer:-

(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."