Batch file to transfer, organize and rename files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Trespassers
Posts: 7
Joined: 30 Jul 2012 04:33

Batch file to transfer, organize and rename files

#1 Post by Trespassers » 30 Jul 2012 04:36

Hello everybody,

My name is Antoine, I'm new on this forum. I'm trying to develop the following batch file :

My point : As a private pilot, I get every month a CD-ROM with updated information in PDF format (approach plates, rules, airport information, etc.), spread in various files and directories.

The way these data are organized and named on that CD doesn't totally fit my needs, thus I would like to automatically transfer chosen data from the CD-ROM to my HD (E:\) in dedicated directories and with a completed name.

For instance, airport visual approach plate files are identified on the CD-ROM with a long name containing amongst others the 4 letters of airport's ICAO name (eg LSZH). I would like the file's name to be automatically completed with the city name (eg ZURICH LSZH).
Airports list is finished and I would fill up a conversion table for the name completion, either inside the batch file, or ideally in a separate text file.
Depending on the PDF's file name, one can also find out what kind of information it contains and therefore in which directory to transfer it. For instance, visual approach charts PDFs name contain also the word "VAC", and I would transfer such files into a VAC folder on my HD.

Currently I'm doing this job manually, but it's typically something that could (and should) be automated.
I have very little experience with batch files, and didn't find out so far how to do it, especially check and modify long file names and how to create/work with a conversion table.


How would you proceed to create such a batch file ? Is there a way doing it, or should I turn towards another language ? Would anybody be nice enough to help me ?

Thanks a lot in advance.
Best regards

Antoine

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file to transfer, organize and rename files

#2 Post by foxidrive » 30 Jul 2012 04:54

The first thing to do is define the job properly and completely, so that a batch file writer doesn't need to recode and retest the batch file again, to add something.


So you would need to define the folders where a certain type of file is coming from, and where it is going too. Charts, logs, maps, whatever.
Showing us a sample of the filenames would help, from each folder that you need to process.

You mentioned that you want to rename files with a 4 character designation and that's easy, but you need a file that has all the 4 character designations on separate lines and followed by the city name.

Is that enough to continue with? See if you can compile a list of the changes.

Trespassers
Posts: 7
Joined: 30 Jul 2012 04:33

Re: Batch file to transfer, organize and rename files

#3 Post by Trespassers » 30 Jul 2012 06:16

Hi foxidrive,

Thank you for your reply.
Let's say on the CD-ROM, files are stored as follows (I don't have it with me, I transcript it by memory):
\120727\eVFR\Full\LS_ADINFO_0001_LSGS_VAC.PDF (where 120727 stands for update number, LS_ADINFO means it's an airport information, LSGS means Sion Airport and VAC = visual approach chart)

The file would be transferred to E:\AIP\VAC\
with the completed name LS_ADINFO_0001_SION_LSGS_VAC.PDF

I would define somewhere that LSGS is related to SION, LSGG to GENEVA, etc.

=> all the CD files containing ADINFO in their name would be tranferred to the folder E:\AIP\VAC\
The other files of the CD would be copied to other folders on my HD, but without name change => if I achieve the above transformation, I think the rest comes quite easy.

Does it help ?
Thanks

Antoine

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file to transfer, organize and rename files

#4 Post by foxidrive » 30 Jul 2012 07:05

Ok.

Don't follow this up elsewhere unless you get no help here. I don't like working on a task when unknown other people are also working on the same task *at other forums*.

I have a comment before providing code - the easiest task would be to copy the CDROM and then do the renames and moving files on your hard drive.

In this case, you might consider this to sort better in a directory list.
LS_ADINFO_0001_LSGS_SION_VAC.PDF
than this
LS_ADINFO_0001_SION_LSGS_VAC.PDF

but that choice is yours.

Are there going to be files in folders other than \120727\eVFR\Full that will be going into E:\AIP\VAC\ ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file to transfer, organize and rename files

#5 Post by foxidrive » 30 Jul 2012 07:11

Also, please post some real file names and the table to translate the 4 character variable, so we can test our code.

Trespassers
Posts: 7
Joined: 30 Jul 2012 04:33

Re: Batch file to transfer, organize and rename files

#6 Post by Trespassers » 30 Jul 2012 07:20

Ok, I provide you more accurate info this evening, when I'm home with the real stuff available.

I'm ok to copy the files then rename.
Regarding city names, I get a more comfortable sorting when the city name stands before ICAO code.

Thanks for your help, won't post elsewhere ;)

Antoine

Trespassers
Posts: 7
Joined: 30 Jul 2012 04:33

Re: Batch file to transfer, organize and rename files

#7 Post by Trespassers » 31 Jul 2012 01:38

Hello again,

There, I tried describing accurately the batch file's task.
Do you think a batch file might be suited to do it?

The CD-ROM contains several folders, but all interesting data are stored in the one named eVFRM\

The folder eVFRM contains one folder named after update number (for instance "120726" for the current update => changing at every release, and an XML file called eVFRM_list.xml :

<?xml version="1.0"?>
-<eVfrmList> <CDRom amdt="008/12" wefDate="26 JUL 2012" number="006/2012"/> <eAip select="Published as of 26 JUL 2012" wef="120726"/> </eVfrmList>

As the case may be, the xml file can be used to find out update number if using a wildcard isn't suited.

The folder 120726 contains 10 folders and an HTML index:

D:\eVFRM\120726>dir
Volume in drive D is LS_eVFRM_006_12
Volume Serial Number is 1A32-994F

Directory of D:\eVFRM\120726

05.07.2012 15:10 <DIR> .
05.07.2012 15:10 <DIR> ..
05.07.2012 15:09 <DIR> AMDT
05.07.2012 15:09 <DIR> Chart
05.07.2012 15:10 <DIR> Full
05.07.2012 10:08 <DIR> ICAO
05.07.2012 15:10 <DIR> SUP
05.07.2012 15:10 <DIR> VFG
05.07.2012 15:10 <DIR> html
05.07.2012 15:10 <DIR> images
18.01.2012 18:47 1'108 index.html
05.07.2012 14:47 2'380 index.html.p7s
05.07.2012 15:10 <DIR> scripts
05.07.2012 15:10 <DIR> styles
2 File(s) 3'488 bytes
12 Dir(s) 0 bytes free




\eVFRM\120726\Chart contains all aera charts (AERA), Visual approach charts (VAC), helicopter approach charts (HEL) + 1 extra file called LS_AGA*.pdf :


Directory of D:\eVFRM\120726\Chart

05.07.2012 15:09 <DIR> .
05.07.2012 15:10 <DIR> ..
05.07.2012 14:37 2'114'776 LS_ADINFO_0000_LFSB_AREA.pdf
05.07.2012 14:37 2'254'452 LS_ADINFO_0000_LFSB_VAC.pdf
05.07.2012 14:38 7'664'298 LS_ADINFO_0000_LSER_HEL.pdf
05.07.2012 14:38 7'485'479 LS_ADINFO_0000_LSEZ_HEL.pdf
05.07.2012 14:38 5'049'638 LS_ADINFO_0000_LSGB_VAC.pdf
05.07.2012 14:38 1'649'330 LS_ADINFO_0000_LSGC_AREA.pdf
05.07.2012 14:38 1'681'581 LS_ADINFO_0000_LSGC_VAC.pdf
05.07.2012 14:38 800'552 LS_ADINFO_0000_LSGE_VAC.pdf
05.07.2012 14:38 5'921'123 LS_ADINFO_0000_LSGG_AREA_A.pdf
05.07.2012 14:38 5'970'059 LS_ADINFO_0000_LSGG_AREA_D.pdf
05.07.2012 14:38 2'288'354 LS_ADINFO_0000_LSGG_HEL.pdf
05.07.2012 14:38 2'298'727 LS_ADINFO_0000_LSGG_VAC_A.pdf
05.07.2012 14:38 2'239'653 LS_ADINFO_0000_LSGG_VAC_D.pdf
05.07.2012 14:38 2'102'456 LS_ADINFO_0000_LSGK_VAC.pdf
05.07.2012 14:38 1'217'927 LS_ADINFO_0000_LSGL_VAC.pdf
05.07.2012 14:39 2'063'568 LS_ADINFO_0000_LSGN_VAC.pdf
05.07.2012 14:39 778'667 LS_ADINFO_0000_LSGP_VAC.pdf
05.07.2012 14:39 783'258 LS_ADINFO_0000_LSGR_VAC.pdf
05.07.2012 14:39 1'946'542 LS_ADINFO_0000_LSGS_AREA.pdf
05.07.2012 14:39 3'281'568 LS_ADINFO_0000_LSGS_VAC.pdf
05.07.2012 14:39 6'733'814 LS_ADINFO_0000_LSGT_VAC.pdf
05.07.2012 14:39 740'919 LS_ADINFO_0000_LSGY_VAC.pdf
05.07.2012 14:39 429'368 LS_ADINFO_0000_LSPA_VAC.pdf
05.07.2012 14:39 3'837'055 LS_ADINFO_0000_LSPF_VAC.pdf
05.07.2012 14:39 678'247 LS_ADINFO_0000_LSPL_VAC.pdf
05.07.2012 14:39 1'960'004 LS_ADINFO_0000_LSPM_VAC.pdf
05.07.2012 14:39 659'543 LS_ADINFO_0000_LSPN_VAC.pdf
05.07.2012 14:39 7'951'416 LS_ADINFO_0000_LSPV_VAC.pdf
05.07.2012 14:39 798'019 LS_ADINFO_0000_LSTO_VAC.pdf
05.07.2012 14:39 911'719 LS_ADINFO_0000_LSTR_VAC.pdf
05.07.2012 14:39 600'455 LS_ADINFO_0000_LSTZ_VAC.pdf
05.07.2012 14:39 536'225 LS_ADINFO_0000_LSXA_HEL.pdf
05.07.2012 14:39 565'090 LS_ADINFO_0000_LSXB_HEL.pdf
05.07.2012 14:39 1'446'214 LS_ADINFO_0000_LSXG_HEL.pdf
05.07.2012 14:40 8'812'038 LS_ADINFO_0000_LSXL_HEL.pdf
05.07.2012 14:40 7'537'129 LS_ADINFO_0000_LSXU_HEL.pdf
05.07.2012 14:40 1'131'770 LS_ADINFO_0000_LSXV_HEL.pdf
05.07.2012 14:40 193'936 LS_ADINFO_0000_LSXY_HEL.pdf
05.07.2012 14:40 3'534'932 LS_ADINFO_0000_LSZA_AREA.pdf
05.07.2012 14:40 3'788'140 LS_ADINFO_0000_LSZA_VAC.pdf
05.07.2012 14:40 2'038'369 LS_ADINFO_0000_LSZB_AREA.pdf
05.07.2012 14:40 2'580'125 LS_ADINFO_0000_LSZB_VAC.pdf
05.07.2012 14:40 2'370'224 LS_ADINFO_0000_LSZC_AREA.pdf
05.07.2012 14:40 2'750'909 LS_ADINFO_0000_LSZC_VAC.pdf
05.07.2012 14:40 881'084 LS_ADINFO_0000_LSZE_VAC.pdf
05.07.2012 14:40 1'396'007 LS_ADINFO_0000_LSZF_VAC.pdf
05.07.2012 14:40 2'080'833 LS_ADINFO_0000_LSZG_AREA.pdf
05.07.2012 14:40 3'365'914 LS_ADINFO_0000_LSZG_VAC.pdf
05.07.2012 14:40 2'325'587 LS_ADINFO_0000_LSZH_AREA_A.pdf
05.07.2012 14:40 2'322'880 LS_ADINFO_0000_LSZH_AREA_D.pdf
05.07.2012 14:40 1'277'168 LS_ADINFO_0000_LSZH_HEL.pdf
05.07.2012 14:41 2'847'794 LS_ADINFO_0000_LSZH_VAC_A.pdf
05.07.2012 14:41 1'479'080 LS_ADINFO_0000_LSZH_VAC_D.pdf
05.07.2012 14:41 759'035 LS_ADINFO_0000_LSZI_VAC.pdf
05.07.2012 14:41 563'192 LS_ADINFO_0000_LSZJ_VAC.pdf
05.07.2012 14:41 859'046 LS_ADINFO_0000_LSZK_VAC.pdf
05.07.2012 14:41 3'119'170 LS_ADINFO_0000_LSZL_AREA.pdf
05.07.2012 14:41 3'151'431 LS_ADINFO_0000_LSZL_VAC.pdf
05.07.2012 14:41 438'212 LS_ADINFO_0000_LSZO_VAC.pdf
05.07.2012 14:41 680'753 LS_ADINFO_0000_LSZP_VAC.pdf
05.07.2012 14:41 721'056 LS_ADINFO_0000_LSZQ_VAC.pdf
05.07.2012 14:41 1'854'368 LS_ADINFO_0000_LSZR_AREA.pdf
05.07.2012 14:41 2'545'364 LS_ADINFO_0000_LSZR_VAC.pdf
05.07.2012 14:41 563'755 LS_ADINFO_0000_LSZS_AREA.pdf
05.07.2012 14:41 697'985 LS_ADINFO_0000_LSZS_VAC.pdf
05.07.2012 14:41 4'277'050 LS_ADINFO_0000_LSZT_VAC.pdf
05.07.2012 14:41 965'392 LS_ADINFO_0000_LSZU_VAC.pdf
05.07.2012 14:41 928'034 LS_ADINFO_0000_LSZV_VAC.pdf
05.07.2012 14:41 590'374 LS_ADINFO_0000_LSZW_VAC.pdf
05.07.2012 14:41 395'571 LS_ADINFO_0000_LSZX_VAC.pdf
05.07.2012 14:41 7'789'419 LS_AGA_0303_APP.pdf
71 File(s) 171'053'222 bytes
2 Dir(s) 0 bytes free


The name structure of these charts is thus : LS_ADINFO_0000_LSZZ_*.pdf, where LSZZ is the aerodrome ICAO code.
The 0000 sequence is useless to me and should be replaced by the city name for better sorting.

All the files starting with LS_ADINFO shall be transferred to E:\AIP\VAC on my HD and the name completed.
The file named LS_AGA*.pdf shall be copied to E:\AIP\AGA

*************************************************

\eVFRM\120726\Full contains several PDFs to spread into various directories on my HD :


Directory of D:\eVFRM\120726\Full

05.07.2012 15:10 <DIR> .
05.07.2012 15:10 <DIR> ..
05.07.2012 14:43 5'311'489 LS_ADINFO_0000_LFSB.pdf
05.07.2012 14:43 608'202 LS_ADINFO_0000_LSER.pdf
05.07.2012 14:43 169'832 LS_ADINFO_0000_LSEZ.pdf
05.07.2012 14:43 178'105 LS_ADINFO_0000_LSGB.pdf
05.07.2012 14:43 4'711'945 LS_ADINFO_0000_LSGC.pdf
05.07.2012 14:43 4'667'398 LS_ADINFO_0000_LSGE.pdf
05.07.2012 14:43 3'245'871 LS_ADINFO_0000_LSGG.pdf
05.07.2012 14:43 2'212'335 LS_ADINFO_0000_LSGG_APPX.pdf
05.07.2012 14:43 2'420'718 LS_ADINFO_0000_LSGK.pdf
05.07.2012 14:43 2'478'868 LS_ADINFO_0000_LSGL.pdf
05.07.2012 14:43 2'439'185 LS_ADINFO_0000_LSGN.pdf
05.07.2012 14:43 170'165 LS_ADINFO_0000_LSGP.pdf
05.07.2012 14:43 4'672'728 LS_ADINFO_0000_LSGR.pdf
05.07.2012 14:43 2'656'959 LS_ADINFO_0000_LSGS.pdf
05.07.2012 14:43 2'425'511 LS_ADINFO_0000_LSGT.pdf
05.07.2012 14:43 2'566'636 LS_ADINFO_0000_LSGY.pdf
05.07.2012 14:44 2'370'165 LS_ADINFO_0000_LSPA.pdf
05.07.2012 14:44 96'013 LS_ADINFO_0000_LSPD.pdf
05.07.2012 14:44 111'766 LS_ADINFO_0000_LSPF.pdf
05.07.2012 14:44 101'570 LS_ADINFO_0000_LSPH.pdf
05.07.2012 14:44 4'645'826 LS_ADINFO_0000_LSPL.pdf
05.07.2012 14:44 2'425'714 LS_ADINFO_0000_LSPM.pdf
05.07.2012 14:44 4'658'401 LS_ADINFO_0000_LSPN.pdf
05.07.2012 14:44 55'799 LS_ADINFO_0000_LSPO.pdf
05.07.2012 14:44 182'412 LS_ADINFO_0000_LSPV.pdf
05.07.2012 14:44 2'330'158 LS_ADINFO_0000_LSTB.pdf
05.07.2012 14:44 176'950 LS_ADINFO_0000_LSTO.pdf
05.07.2012 14:44 2'365'685 LS_ADINFO_0000_LSTR.pdf
05.07.2012 14:44 4'659'999 LS_ADINFO_0000_LSTZ.pdf
05.07.2012 14:44 2'367'018 LS_ADINFO_0000_LSXA.pdf
05.07.2012 14:44 131'004 LS_ADINFO_0000_LSXB.pdf
05.07.2012 14:44 136'604 LS_ADINFO_0000_LSXG.pdf
05.07.2012 14:44 149'458 LS_ADINFO_0000_LSXL.pdf
05.07.2012 14:44 2'347'542 LS_ADINFO_0000_LSXU.pdf
05.07.2012 14:44 2'355'029 LS_ADINFO_0000_LSXV.pdf
05.07.2012 14:44 616'514 LS_ADINFO_0000_LSXY.pdf
05.07.2012 14:44 7'086'942 LS_ADINFO_0000_LSZA.pdf
05.07.2012 14:44 2'749'575 LS_ADINFO_0000_LSZB.pdf
05.07.2012 14:45 2'775'515 LS_ADINFO_0000_LSZC.pdf
05.07.2012 14:45 4'656'425 LS_ADINFO_0000_LSZE.pdf
05.07.2012 14:45 2'491'983 LS_ADINFO_0000_LSZF.pdf
05.07.2012 14:45 2'912'011 LS_ADINFO_0000_LSZG.pdf
05.07.2012 14:45 3'902'963 LS_ADINFO_0000_LSZH.pdf
05.07.2012 14:45 9'459'697 LS_ADINFO_0000_LSZH_APPHEL.pdf
05.07.2012 14:45 2'370'593 LS_ADINFO_0000_LSZI.pdf
05.07.2012 14:45 2'349'880 LS_ADINFO_0000_LSZJ.pdf
05.07.2012 14:45 4'661'774 LS_ADINFO_0000_LSZK.pdf
05.07.2012 14:45 2'438'964 LS_ADINFO_0000_LSZL.pdf
05.07.2012 14:45 187'899 LS_ADINFO_0000_LSZN.pdf
05.07.2012 14:45 2'444'976 LS_ADINFO_0000_LSZO.pdf
05.07.2012 14:45 2'371'796 LS_ADINFO_0000_LSZP.pdf
05.07.2012 14:45 4'666'901 LS_ADINFO_0000_LSZQ.pdf
05.07.2012 14:45 2'534'794 LS_ADINFO_0000_LSZR.pdf
05.07.2012 14:46 7'062'827 LS_ADINFO_0000_LSZS.pdf
05.07.2012 14:46 107'353 LS_ADINFO_0000_LSZT.pdf
05.07.2012 14:46 2'369'845 LS_ADINFO_0000_LSZU.pdf
05.07.2012 14:46 2'352'455 LS_ADINFO_0000_LSZV.pdf
05.07.2012 14:46 99'399 LS_ADINFO_0000_LSZW.pdf
05.07.2012 14:46 2'365'888 LS_ADINFO_0000_LSZX.pdf
05.07.2012 14:46 289'718 LS_AGA_0000.pdf
05.07.2012 14:46 3'292'142 LS_AGA_0000_APP.pdf
05.07.2012 14:46 168'858 LS_AGA_0000_APPA.pdf
05.07.2012 14:46 243'403 LS_AGA_0200.pdf
05.07.2012 14:46 2'640'686 LS_AGA_0300.pdf
05.07.2012 14:46 851'594 LS_AGA_0300_APPA.pdf
05.07.2012 14:46 128'470 LS_AGA_0301_HEL.pdf
05.07.2012 14:46 82'996 LS_AGA_0302.pdf
05.07.2012 14:46 90'407 LS_AGA_0303.pdf
05.07.2012 14:46 6'974'868 LS_COM_0200_APP.pdf
05.07.2012 14:46 189'629 LS_COR_0000.pdf
05.07.2012 14:46 222'510 LS_GEN_0100.pdf
05.07.2012 14:46 143'642 LS_GEN_0102.pdf
05.07.2012 14:46 144'586 LS_GEN_0105.pdf
05.07.2012 14:46 1'934'909 LS_GEN_0200.pdf
05.07.2012 14:46 5'134'371 LS_MAP_0102.pdf
05.07.2012 14:46 982'824 LS_MAP_0200.pdf
05.07.2012 14:47 535'235 LS_RAC_0102.pdf
05.07.2012 14:47 14'696'595 LS_RAC_0102_PLN.pdf
05.07.2012 14:47 2'515'591 LS_RAC_0301.pdf
05.07.2012 14:47 2'650'229 LS_RAC_0302.pdf
05.07.2012 14:47 749'013 LS_RAC_0400.pdf
05.07.2012 14:47 1'546'051 LS_RAC_0400_APP.pdf
05.07.2012 14:47 135'718 LS_RAC_0400_PRE00.pdf
05.07.2012 14:47 3'534'365 LS_RAC_0401.pdf
05.07.2012 14:47 281'193 LS_RAC_0503_PERM.pdf
05.07.2012 14:47 568'984 LS_RAC_0503_TEMPO.pdf
05.07.2012 14:47 250'293 LS_RAC_0800.pdf
05.07.2012 14:47 372'533 LS_RAC_0800_APPA.pdf
05.07.2012 14:47 97'291 LS_RAC_0800_APPB.pdf
05.07.2012 14:47 1'571'888 LS_VFR_0000.pdf
90 File(s) 200'660'621 bytes
2 Dir(s) 0 bytes free

All the files starting with LS_ADINFO (aerodrome information) shall be transferred together with the charts to E:\AIP\VAC on my HD and the name completed.
The files named LS_AGA*.pdf shall be copied to E:\AIP\AGA
The files named LS_COM*.pdf shall be copied to E:\AIP\COM
The files named LS_COR*.pdf shall be copied to E:\AIP\COR
The files named LS_GEN*.pdf shall be copied to E:\AIP\GEN
The files named LS_MAP*.pdf shall be copied to E:\AIP\MAP
The files named LS_RAC*.pdf shall be copied to E:\AIP\RAC
The files named LS_VFR*.pdf shall be copied to E:\AIP\VFR

*************************************************

For the rest of the CD-ROM:

The directory \eVFRM\120726\AMDT shall be copied with its content to E:\AIP\AMDT
The directory \eVFRM\120726\SUP shall be copied with its content to E:\AIP\SUP
The directory \eVFRM\120726\VFG shall be copied with its content to E:\AIP\VFG

*************************************************

Eventually, the XML file called eVFRM_list.xml shall be copied to E:\AIP, so that I can easily track the update version.

Thanks a lot for your support.
Best regards

Antoine

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file to transfer, organize and rename files

#8 Post by foxidrive » 31 Jul 2012 03:01

I think this could do the job but it is untested. Copy your E:\AIP folder somewhere else for a backup and try this.
Note that it expects the folders on E: to already exist.

You will have to create this file first "e:\AIP\translate_list.txt" and inside it create a list of aerodrome ICAO codes and the city name, in this format

LFSB Singapore
LSER Melbourne
LSEZ Toronto


Then when you run the batch file you will only get filenames echoed to the screen - this is to check if I got the items correct so you can see if the city names are in the right place and if the filenames look right.

Each two lines will be followed by a 'press any key to continue' message and eventually an 'aborting' message when it will end.

If the names look right after you have created the translation file then change

"echo copy /b /y" to "copy /b /y " in two places

and remove these three lines

echo aborting
pause
goto :EOF



Let me know if the filenames are wrong and paste an example of the errors.



Code: Select all

@echo off
set cdrom="d:"

for /f "delims=" %%a in ('dir "%cdrom%\eVFRM\" /ad /b') do set "update=%%a"

echo Update release is "%update%"

for %%a in ("%cdrom%\eVFRM\%update%\chart\LS_ADINFO_*") do (
for /f "tokens=1-4,* delims=_" %%b in ("%%a") do (
for /f "tokens=2" %%z in ('find /i "%%e" ^< "e:\AIP\translate_list.txt"') do (
echo copying "E:\AIP\VAC\%%b_%%c_%%z_%%e_%%f"
echo copy /b /y "%%a" "E:\AIP\VAC\%%b_%%c_%%z_%%e_%%f"
pause
)
)
)


for %%a in ("%cdrom%\eVFRM\%update%\full\LS_ADINFO_*") do (
for /f "tokens=1-5 delims=_." %%b in ("%%a") do (
for /f "tokens=2" %%z in ('find /i "%%e" ^< "e:\AIP\translate_list.txt"') do (
echo copying "E:\AIP\VAC\%%b_%%c_%%z_%%e.%%f"
echo copy /b /y "%%a" "E:\AIP\VAC\%%b_%%c_%%z_%%e.%%f"
pause
)
)
)

echo aborting
pause
goto :EOF

echo copying PDF files
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_AGA*.pdf" "E:\AIP\AGA" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_COM*.pdf" "E:\AIP\COM" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_COR*.pdf" "E:\AIP\COR" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_GEN*.pdf" "E:\AIP\GEN" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_MAP*.pdf" "E:\AIP\MAP" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_RAC*.pdf" "E:\AIP\RAC" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_VFR*.pdf" "E:\AIP\VFR" >nul


xcopy "%cdrom%\eVFRM\%update%\AMDT\*.*" "E:\AIP\AMDT\" /s /h /e /k /f /c
xcopy "%cdrom%\eVFRM\%update%\SUP\*.*"  "E:\AIP\SUP\"  /s /h /e /k /f /c
xcopy "%cdrom%\eVFRM\%update%\VFG\*.*"  "E:\AIP\VFG\"  /s /h /e /k /f /c
copy /b /y "%cdrom%\eVFRM\eVFRM_list.xml"  "E:\AIP" >nul
echo Done.
pause

Trespassers
Posts: 7
Joined: 30 Jul 2012 04:33

Re: Batch file to transfer, organize and rename files

#9 Post by Trespassers » 31 Jul 2012 04:18

Wow ! I'm really amazed, thank you so much ! I'm going to test it and let you know ASAP.

Have a pleasant day
Yours,

Antoine

Trespassers
Posts: 7
Joined: 30 Jul 2012 04:33

Re: Batch file to transfer, organize and rename files

#10 Post by Trespassers » 31 Jul 2012 06:08

Hi foxidrive,

I'm pretty amazed, the batch files works pretty well indeed. There are only 2 small issues :

1) the %%b variable in copy /b /y "%%a" "E:\AIP\VAC\%%b_%%c_%%z_%%e_%%f"
contains "d:\eVFRM\120726\chart\LS" instead of "LS":

Update release is "120726"
copying "E:\AIP\VAC\d:\eVFRM\120726\chart\LS_ADINFO_BALE_MULHOUSE_LFSB_AREA.pdf"

copy /b /y "d:\eVFRM\120726\chart\LS_ADINFO_0000_LFSB_AREA.pdf" "E:\AIP\VAC\d:\e
VFRM\120726\chart\LS_ADINFO_BALE_MULHOUSE_LFSB_AREA.pdf"
Press any key to continue . . .

By changing the line to copy /b /y "%%a" "E:\AIP\VAC\%%c_%%z_%%e_%%f" it works, but I loose the "LS_" part of the name of the file (ADINFO*.pdf instead of LS_ADINFO*.pdf).

2) the second part...
for %%a in ("%cdrom%\eVFRM\%update%\full\LS_ADINFO_*") do (
for /f "tokens=1-5 delims=_." %%b in ("%%a") do (
for /f "tokens=2" %%z in ('find /i "%%e" ^< "e:\AIP\translate_list.txt"') do (
echo copying "E:\AIP\VAC\%%b_%%c_%%z_%%e.%%f"
echo copy /b /y "%%a" "E:\AIP\VAC\%%b_%%c_%%z_%%e.%%f"
pause

...works pretty fine for all the files but 2, having an extra suffix after ICAO code and before the extension :

LS_ADINFO_0000_LSGG_APPX.PDF
and
LS_ADINFO_0000_LSZH_APPHEL.PDF

become thus

ADINFO_GENEVE_LSGG.APPX
and
ADINFO_ZURICH_LSZH.APPHEL


I'm quite unfamiliar with the "token... delims" instruction you used, I will do some trial and error to figure out how exactly this instruction works and find a fix.

*********************
EDIT 1:
For that second point, I found the following workaround, works ok:
IF %%f == pdf (
echo copying "E:\AIP\VAC\%%c_%%z_%%e.%%f"
copy /b /y "%%a" "E:\AIP\VAC\%%c_%%z_%%e.%%f"
rem pause
) ELSE (
echo copying "E:\AIP\VAC\%%c_%%z_%%e_%%f.pdf"
copy /b /y "%%a" "E:\AIP\VAC\%%c_%%z_%%e_%%f.pdf"
rem pause
)
*********************

EDIT 2:
For the first point, I found a workaround by replacing %bb with LS_

Works flawless !
*********************

Thank you so much for your nice help, I really, really appreciate !

Best regards
Antoine

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file to transfer, organize and rename files

#11 Post by foxidrive » 31 Jul 2012 11:12

I'm glad you were able to repair the issues Antoine.

For what it is worth, the edits below in colour should fix the %%b issue. Your solution to the other issue is great but add a /i in IF /i "%%f"=="pdf" (
so that any upper case files are copied too.

@echo off
set cdrom="d:"

for /f "delims=" %%a in ('dir "%cdrom%\eVFRM\" /ad /b') do set "update=%%a"

echo Update release is "%update%"

pushd "%cdrom%\eVFRM\%update%\chart\"
for %%a in ("LS_ADINFO_*") do (

for /f "tokens=1-4,* delims=_" %%b in ("%%a") do (
for /f "tokens=2" %%z in ('find /i "%%e" ^< "e:\AIP\translate_list.txt"') do (
echo copying "E:\AIP\VAC\%%b_%%c_%%z_%%e_%%f"
echo copy /b /y "%%a" "E:\AIP\VAC\%%b_%%c_%%z_%%e_%%f"
pause
)
)
)
popd

pushd "%cdrom%\eVFRM\%update%\full\"
for %%a in ("LS_ADINFO_*") do (
for /f "tokens=1-5 delims=_." %%b in ("%%a") do (
for /f "tokens=2" %%z in ('find /i "%%e" ^< "e:\AIP\translate_list.txt"') do (
echo copying "E:\AIP\VAC\%%b_%%c_%%z_%%e.%%f"
echo copy /b /y "%%a" "E:\AIP\VAC\%%b_%%c_%%z_%%e.%%f"
pause
)
)
)
popd

echo aborting
pause
goto :EOF

echo copying PDF files
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_AGA*.pdf" "E:\AIP\AGA" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_COM*.pdf" "E:\AIP\COM" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_COR*.pdf" "E:\AIP\COR" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_GEN*.pdf" "E:\AIP\GEN" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_MAP*.pdf" "E:\AIP\MAP" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_RAC*.pdf" "E:\AIP\RAC" >nul
copy /b /y "%cdrom%\eVFRM\%update%\full\LS_VFR*.pdf" "E:\AIP\VFR" >nul


xcopy "%cdrom%\eVFRM\%update%\AMDT\*.*" "E:\AIP\AMDT\" /s /h /e /k /f /c
xcopy "%cdrom%\eVFRM\%update%\SUP\*.*" "E:\AIP\SUP\" /s /h /e /k /f /c
xcopy "%cdrom%\eVFRM\%update%\VFG\*.*" "E:\AIP\VFG\" /s /h /e /k /f /c
copy /b /y "%cdrom%\eVFRM\eVFRM_list.xml" "E:\AIP" >nul
echo Done.
pause

Trespassers
Posts: 7
Joined: 30 Jul 2012 04:33

Re: Batch file to transfer, organize and rename files

#12 Post by Trespassers » 01 Aug 2012 03:34

Thank you so much foxidrive, your fix works great - it's smarter than mine - and I learned a new dos function I wasn't aware of : pushd/popd.

In the meantime I also improved the overall routine with variable target drive and automated subfolders creation.
I was pretty confident a batch file would be the ideal kind of tool for such a task, but I definitely wouldn't have figured out by myself how to do it the way you did.
Therefore I cannot thank you enough for your great and efficient support.

Best regards
Antoine

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file to transfer, organize and rename files

#13 Post by foxidrive » 01 Aug 2012 13:28

It's nice to hear that you are enhancing the features around my framework. That's the best way to learn - add things, fix it when it breaks, and change bits.

All the best

Post Reply