Welcome
Username or Email:

Password:


Missing Code




[ ]
[ ]
Online
  • Guests: 21
  • Members: 0
  • Newest Member: omjtest
  • Most ever online: 396
    Guests: 396, Members: 0 on 12 Jan : 12:51
Members Birthdays:
No birthdays today

Next birthdays
06/02 GreySoul (45)
06/02 GluD (35)
06/02 northern_lightning (41)
Contact
If you need assistance, please send an email to forum at 4hv dot org. To ensure your email is not marked as spam, please include the phrase "4hv help" in the subject line. You can also find assistance via IRC, at irc.shadowworld.net, room #hvcomm.
Support 4hv.org!
Donate:
4hv.org is hosted on a dedicated server. Unfortunately, this server costs and we rely on the help of site members to keep 4hv.org running. Please consider donating. We will place your name on the thanks list and you'll be helping to keep 4hv.org alive and free for everyone. Members whose names appear in red bold have donated recently. Green bold denotes those who have recently donated to keep the server carbon neutral.


Special Thanks To:
  • Aaron Holmes
  • Aaron Wheeler
  • Adam Horden
  • Alan Scrimgeour
  • Andre
  • Andrew Haynes
  • Anonymous000
  • asabase
  • Austin Weil
  • barney
  • Barry
  • Bert Hickman
  • Bill Kukowski
  • Blitzorn
  • Brandon Paradelas
  • Bruce Bowling
  • BubeeMike
  • Byong Park
  • Cesiumsponge
  • Chris F.
  • Chris Hooper
  • Corey Worthington
  • Derek Woodroffe
  • Dalus
  • Dan Strother
  • Daniel Davis
  • Daniel Uhrenholt
  • datasheetarchive
  • Dave Billington
  • Dave Marshall
  • David F.
  • Dennis Rogers
  • drelectrix
  • Dr. John Gudenas
  • Dr. Spark
  • E.TexasTesla
  • eastvoltresearch
  • Eirik Taylor
  • Erik Dyakov
  • Erlend^SE
  • Finn Hammer
  • Firebug24k
  • GalliumMan
  • Gary Peterson
  • George Slade
  • GhostNull
  • Gordon Mcknight
  • Graham Armitage
  • Grant
  • GreySoul
  • Henry H
  • IamSmooth
  • In memory of Leo Powning
  • Jacob Cash
  • James Howells
  • James Pawson
  • Jeff Greenfield
  • Jeff Thomas
  • Jesse Frost
  • Jim Mitchell
  • jlr134
  • Joe Mastroianni
  • John Forcina
  • John Oberg
  • John Willcutt
  • Jon Newcomb
  • klugesmith
  • Leslie Wright
  • Lutz Hoffman
  • Mads Barnkob
  • Martin King
  • Mats Karlsson
  • Matt Gibson
  • Matthew Guidry
  • mbd
  • Michael D'Angelo
  • Mikkel
  • mileswaldron
  • mister_rf
  • Neil Foster
  • Nick de Smith
  • Nick Soroka
  • nicklenorp
  • Nik
  • Norman Stanley
  • Patrick Coleman
  • Paul Brodie
  • Paul Jordan
  • Paul Montgomery
  • Ped
  • Peter Krogen
  • Peter Terren
  • PhilGood
  • Richard Feldman
  • Robert Bush
  • Royce Bailey
  • Scott Fusare
  • Scott Newman
  • smiffy
  • Stella
  • Steven Busic
  • Steve Conner
  • Steve Jones
  • Steve Ward
  • Sulaiman
  • Thomas Coyle
  • Thomas A. Wallace
  • Thomas W
  • Timo
  • Torch
  • Ulf Jonsson
  • vasil
  • Vaxian
  • vladi mazzilli
  • wastehl
  • Weston
  • William Kim
  • William N.
  • William Stehl
  • Wesley Venis
The aforementioned have contributed financially to the continuing triumph of 4hv.org. They are deserving of my most heartfelt thanks.
Forums
4hv.org :: Forums :: Computer Science
« Previous topic | Next topic »   

DOS File Command

Move Thread LAN_403
Nucleophobe
Fri Jan 19 2007, 11:28PM Print
Nucleophobe Registered Member #108 Joined: Thu Feb 09 2006, 11:44PM
Location: Billings, MT
Posts: 61
Does anyone know what DOS copy command you would use to copy one file into multiple folders??
For instance, I have in my directory:

foo.txt
DirectoryA\
DirectoryB\
DirectoryC\
Dire ctoryD\
DirectoryE\
...

I thought something like "copy foo.txt *\" would work, but it gives syntax errors (doesn't like a wildcard for the folder name). Does anyone know how to do this? I could do it with a VB script instead maybe, but I don't have very much experience there.

Thanks,

Ken A.
Back to top
Alex
Sat Jan 20 2007, 12:37AM
Alex Geometrically Frustrated
Registered Member #6 Joined: Thu Feb 02 2006, 04:18AM
Location: Bowdoin, Maine
Posts: 373
From directory foo with file bar..
FOR /F %i IN ('dir /B /AD .') DO copy foo %i\.
Back to top
Nucleophobe
Sun Jan 21 2007, 08:12PM
Nucleophobe Registered Member #108 Joined: Thu Feb 09 2006, 11:44PM
Location: Billings, MT
Posts: 61
Thanks Alex. I had to play with it a bit but it worked like a charm (the folders has spaces in their names)
Back to top
Nucleophobe
Tue Feb 06 2007, 03:04AM
Nucleophobe Registered Member #108 Joined: Thu Feb 09 2006, 11:44PM
Location: Billings, MT
Posts: 61
Ok, I have another couple questions.

I have this code, which reads the first and second token from foo.txt (which is someones first and last name), then creates a folder "lastname, firstname" and copies foo.txt to the new folder with a new filename as well as a second file that is the same as "foo.txt" except it looks something like "foo-otherstuff.prt".

My code works, but there is three problems.

A) what is the best way to read ONLY the second and third token from a file, ignoring all lines after the first?

B) I kept getting more folders than expected, which were named ",foo.txt" (the reason for the skip label)

C) Xcopy prompts me to answer whether the destination is a file or directory. the "/i" switch suppressed this prompt under the assumption that the destination is a directory, but is there a way to suppress the prompt under the assumption that the destination is a file? (there are 100+ files!)



FOR %%i IN (*.txt) DO call :read_name %%i


:read_name
REM store filename in variable
set _file=%1

REM store file contents in string
Set /P _filestuff=<%_file%

REM look through first 20 characters, storing tokens 2 and 3
FOR /F "tokens=2,3" %%i IN ("%_filestuff:~1,20%") DO call :copy_files %%i, %%j



:copy_files
set _firstname=%1
set _lastname=%2

IF "%_lastname%" == "" goto skip

set _folder=%_lastname%, %_firstname%
IF NOT EXIST "%_folder%" mkdir "%_folder%"
copy %_file% "%_folder%\WA4 - %_folder%.txt"
xcopy /Y "%_file:~0,-4%*.prt" "%_folder%\WA4 - %_folder%.prt"

:skip


Unfortunately, "copy" cannot handle wildcards like xcopy

Thanks!
-Ken
Back to top

Moderator(s): Chris Russell, Noelle, Alex, Tesladownunder, Dave Marshall, Dave Billington, Bjørn, Steve Conner, Wolfram, Kizmo, Mads Barnkob

Go to:

Powered by e107 Forum System
 
Legal Information
This site is powered by e107, which is released under the GNU GPL License. All work on this site, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. By submitting any information to this site, you agree that anything submitted will be so licensed. Please read our Disclaimer and Policies page for information on your rights and responsibilities regarding this site.