Moving Files to Specific Folders

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Moving Files to Specific Folders

Post by MigrationUser »

26 Jan 2009 17:45
Muzner

Hello,

I've got a project that I'm working on that involves barcodes. I currently have a batch file that runs a program to scan barcodes on a multi-page tif. It splits the tif file into separate files named after the barcode it finds.

The file looks like this:
START C:\bardecode.exe -g -x settings.xml -X output.xml --TifSplitPath C:\Scanning\TiffOutput\%%s_%%d.tif

After its done with the processing, I run another file on the output of that batch file, it renames the files by adding a time stamp.

This is the time stamp file:

Code: Select all

@Echo Off
@For /F "tokens=2-4 delims=/ " %%A in ('Date /t') do @(
Set Month=%%A
Set Day=%%B
Set Year=%%C
Set All=%%C%%A%%B
)
@For /F "tokens=1-6 delims=: " %%A in ('Time /t') do @(
Set Hour=%%A
Set Min=%%B
Set HourMin=%%A%%B
)
@For %%a in ("*.tif") do copy %%a "C:\Scanning\TiffOutput\%%~na_%All%_%HourMin%.tif"

There are several things I would like to accomplish, but I'm not really sure if it is possible. I would like to combine those two so that once the barcode program is done processing the file, it will rename those files with the date. Also, when it finishes, the files look something like this:

D09-1234_1_2009122_1139.tif

or

R09-1234_1_2009122_1139.tif

They all start with different characters, such as S, R, D, GE, HH, etc...

Is there a batch file I could run that would move those files depending upon the starting character into certain folders? Such as all S files be moved into the Surgical Folder?

Thanks so much for the help, let me know if it needs clarification, I know I'm probably asking a lot.

----------------------------

#2 26 Jan 2009 18:31
avery_larry


I think just the standard move command:

Code: Select all

move s*.* "path\whatever directory you want\"
move d*.* "path\whatever other directory\"
Or do I not understand what you want?

Last edited by avery_larry (26 Jan 2009 18:31)

----------------------------

#3 26 Jan 2009 18:39
Muzner


Yes that does work for that part, which is really helpful. I also wanted to know, after the time stamp has been applied to the original files and then the files are moved, is there a way to delete the source files that were created?

----------------------------

#4 26 Jan 2009 20:22
avery_larry


rename instead of copy?

Or just use move instead of copy:

Code: Select all

@For %%a in ("*.tif") do move "%%a" "C:\Scanning\TiffOutput\%%~na_%All%_%HourMin%.tif"
But if TiffOutput is just a temporary location you could rename first and then move:

Code: Select all

@For %%a in ("*.tif") do ren "%%a" "%%~na_%All%_%HourMin%.tif"
move s*.tif "path\directory"
move d*.tif "path\different directory"
Is that getting closer to what you need?

Last edited by avery_larry (26 Jan 2009 20:23)

----------------------------

#5 29 Jan 2009 18:51
Muzner


Sorry about not getting back to you, I've been rather busy at work with other stuff. This would seem to help, but I can't seem to get it working right.

Code: Select all

@Echo Off
@For /F "tokens=2-4 delims=/ " %%A in ('Date /t') do @(
Set Month=%%A
Set Day=%%B
Set Year=%%C
Set All=%%C%%A%%B
)
@For /F "tokens=1-6 delims=: " %%A in ('Time /t') do @(
Set Hour=%%A
Set Min=%%B
Set HourMin=%%A%%B
)
@For %%a in ("*.tif") do copy %%a "C:\Scanning\TiffOutput\Process\%%~na_%All%_%HourMin%.tif"

move d*.tif "C:\Scanning\TiffOutput\Test\Derms\"
move p*.tif "C:\Scanning\TiffOutput\Test\Paps\"
move ge*.tif "C:\Scanning\TiffOutput\Test\Gastro\"
move r*.tif "C:\Scanning\TiffOutput\Test\Surgical\"
move hh*.tif "C:\Scanning\TiffOutput\Test\Hilton\"
move _*.tif "C:\Scanning\TiffOutput\Test\QA\"
These are the different ones that need to be moved depending on the type of batch that is run. I can get it to move to the process folder, but it doesn't seem to do anything after that. Do I need to have it change folders some how?

Thanks again for the help.

----------------------------

#6 29 Jan 2009 20:20
avery_larry


I think I'd do this:

Code: Select all

@For %%a in ("d*.tif") do copy %%a "C:\Scanning\TiffOutput\Test\Derms\%%~na_%All%_%HourMin%.tif"
@For %%a in ("p*.tif") do copy %%a "C:\Scanning\TiffOutput\Test\Paps\%%~na_%All%_%HourMin%.tif"
@For %%a in ("ge*.tif") do copy %%a "C:\Scanning\TiffOutput\Test\ge\%%~na_%All%_%HourMin%.tif"
etc. Copy and rename directly to your final destination.

As far as what you had, you probably needed to do this to make it work:

Code: Select all

move C:\Scanning\TiffOutput\Process\d*.tif "C:\Scanning\TiffOutput\Test\Derms\"
move C:\Scanning\TiffOutput\Process\p*.tif "C:\Scanning\TiffOutput\Test\Paps\"
move C:\Scanning\TiffOutput\Process\ge*.tif "C:\Scanning\TiffOutput\Test\Gastro\"
or:

Code: Select all

cd /d c:\Scanning\TiffOutput\Process
move d*.tif "C:\Scanning\TiffOutput\Test\Derms\"
move p*.tif "C:\Scanning\TiffOutput\Test\Paps\"
move ge*.tif "C:\Scanning\TiffOutput\Test\Gastro\"
----------------------------

#7 03 Feb 2009 14:51
Muzner


Thanks a lot for the help. That worked out great for moving and adding the time stamps. I had one more question, is it possible for a batch file to recognize attributes of a particular file it is processing? I'm trying to see if there's a way to incorporate an if statement in there to move all tif files that are more than one page to a different folder for further processing.

----------------------------

#8 03 Feb 2009 16:37
bluesxman


CMD can't obtain that sort of information on its own, but you might be able to find a command line utility that can get information from the header.

A quick google turned up these sites, which I categorically cannot vouch for:

https://www.sentex.net/~mwandel/jhead/
https://www.hugsan.com/EXIFutils/

cmd | *sh | ruby | chef

----------------------------

#9 03 Feb 2009 16:40
Muzner


I was afraid of that, it didn't seem to come up on any documentation for the command prompt. I'll look into trying one of those programs instead or something like it.

Thanks!
Post Reply