Computing.Net > Forums > Programming > Copying certain files from folders

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Copying certain files from folders

Reply to Message Icon

Name: it_NY
Date: October 8, 2009 at 06:23:13 Pacific
OS: Windows XP
Product: Microsoft Windows xp professional edition
Subcategory: Batch
Comment:

I have several folders that get created on a daily basis. For example:
20091001.000
20091002.000
20091003.000
Etc...

As you can see the date changes everyday for the folder name but .000 remains constant.

In these folders are daily reports in PDF format. I would like the ability to copy certain pdf's (not all) within these folders to another network drive keeping the folder structure the same on the drive that copies are being stored

So if the R: drive hosted folders:
20091001.000
20091002.000
20091003.000

I would want to copy the folders but only select pdfs from them to the H: drive. This wo uld be done on a daily basis

Currently I am using the following script:

for /d %%a in (R:\Reports\????????.000) do xcopy /e /i /-y "%%~fa" "H:\%%~nxa"

This copys all the contents of the folder from one drive to the other. Is there a way to modify this to copy specific files from fthe folder? if i have files daily called A.pdf B.pdf how would i adjust the command?

Any help would be appreciated

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: it_NY
Date: October 8, 2009 at 06:49:39 Pacific
Reply:

Currently I am using the following script:

for /d %%a in (R:\Reports\????????.000) do xcopy /e /i /-y "%%~fa" "H:\%%~nxa"

This copys all the contents of the folder from one drive to the other. Is there a way to modify this to copy specific files from fthe folder? if i have files daily called A.pdf B.pdf how would i adjust the command?


0

Response Number 2
Name: Mechanix2Go
Date: October 8, 2009 at 09:43:15 Pacific
Reply:

Do you only want the most recent A.pdf etc?


=====================================
Helping others achieve escape felicity

M2


0

Response Number 3
Name: it_NY
Date: October 8, 2009 at 09:48:42 Pacific
Reply:

yes i was going to use the /d command to only upload changed files


0

Response Number 4
Name: Mechanix2Go
Date: October 8, 2009 at 10:14:38 Pacific
Reply:

Unless I'm missing the obvious, once you're current, you only need to copy the most recent folder's files.

This navigates itself to the most recent folder within R:\Reports and copies all the ?.pdfs.

====================================
@echo off & setLocal enableDELAYedexpansion

pushd R:\Reports

for /f "tokens=* delims= " %%a in ('dir/b/ad/o-n *.000') do (
pushd "%%a"
goto :done
)
:done

copy ?.pdf h:\


=====================================
Helping others achieve escape felicity

M2


0

Response Number 5
Name: it_NY
Date: October 8, 2009 at 10:56:46 Pacific
Reply:

Thanks for the script it works yes and no.

To explain further this is more of what I want to do

R:/20091001.00/a.pdf copy to > H:/20091001.00/a.pdf
R:/20091002.00/a.pdf copy to > H:/20091002.00/a.pdf
R:/20091003.00/a.pdf copy to > H:/20091002.00/a.pdf
R:/20091004.00/a.pdf copy to > H:/20091002.00/a.pdf

Pretty much want a mirror image. and for it to create the same folder structure of YYYYMMDD.000 automatically

And then if the batch is run the next day, it wont try to recopy all the old folders again and only the new ones

Hope that better explains it!

Thanks for the assistance :)


0

Related Posts

See More



Response Number 6
Name: nbrane
Date: October 12, 2009 at 16:51:59 Pacific
Reply:

xcopy has a couple of options that migh help:
/M copies only those files that have the archive-bit set, and
switches off the archive bit (thus marking them as "copied"
and avoiding subsequent copying). You only need to verify
that the incoming files have this bit switched on ("attrib"
command shows "A" for the files.)
/Ddate copies only those files newer (more recent) than the
date specified after "D". this requires that the incoming files
dates are correct/synchronized with your system.
ps: it looks like, from viewing posts, Msft
would be doing a HUGE service if it had a
"mirror" utility w/various options. hey,
Bill G, like my idea? HIRE ME (just kidding)
(but submit only 15 million for the idea...thats nuts to you guys anyway, an i need it...


0

Response Number 7
Name: it_NY
Date: October 13, 2009 at 08:39:31 Pacific
Reply:

how would i adjust this script for a specific file instead of the whole folder?

for /d %%a in (R:\Reports\????????.000) do xcopy /e /i /-y "%%~fa" "H:\%%~nxa"

This copies R:\YYYYMMDD.000 to H:\YYYYMMDD.000 and all its contents. I want it to be able to copy only certain files for example A.pdf.

I tried modifying the script the folllowing way but it is not working:

for /d %%a in (R:\Reports\????????.000\a.pdf) do xcopy /e /i /-y "%%~fa" "H:\%%~nxa"


0
Reply to Message Icon

enter file path to a vari... print the song The Twelve...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Copying certain files from folders

copy files from folder A to folder B .... www.computing.net/answers/programming/copy-files-from-folder-a-to-folder-b-/20177.html

Copy Paste Files and Folder www.computing.net/answers/programming/copy-paste-files-and-folder/20150.html

Shell script to copy a file from local drive www.computing.net/answers/programming/shell-script-to-copy-a-file-from-local-drive-/18791.html