dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
545
share rss forum feed


rudnicke
Premium
join:2004-10-23
Rantoul, IL
kudos:4

Need help with MOVE command in BAT

I have a bat file setup to move data from one location to another each night.

This bat file only moves PDF files. Here is an example:

cd X:\ENDDAY\BR02
md .\%Year%%Month%%Day%
cd %Year%%Month%%Day%
move /Y Q:\02\#BIL01\PFW\*.*
move /Y Q:\02\#BIL01S\PFW\*.*
move /Y Q:\02\#BIL01W\PFW\*.*
move /Y Q:\02\#BIL01G\PFW\*.*
move /Y Q:\02\W1\DATABASE\*.*
move /Y Q:\02\W1\PFW\*.*
move /Y Q:\02\W1\SPOWERS\*.*

The source where the files come from has started saving the files in random folders (as you can tell there are several locations listed). Is there a way, using the move command, that I can scan Q:\02\ for *.* and move it?

Something like: move /Y Q:\02\*.pdf (how would I tell it to scan all the subfolders under Q:\02\)?
--
I did have a sig, but I had to remove it because my political views were too 'wrong' for some users on DSLr.

dave
Premium,MVM
join:2000-05-04
not in ohio
kudos:8
Time to learn about the for command?

8744675

join:2000-10-10
Decatur, GA
reply to rudnicke
The best place to find DOS batch command help is Computer Hope at »www.computerhope.com/msdos.htm.

I learned alot from this site and even learned how to get file metadata attributes such as date-time and file size and use it to control what happens, and how to execute multiple commands after an if statement by using curly brackets to enclose them.

if xxxxx {
do this
do that
do something else
}


rudnicke
Premium
join:2004-10-23
Rantoul, IL
kudos:4
reply to rudnicke
Thanks.


rudnicke
Premium
join:2004-10-23
Rantoul, IL
kudos:4
reply to rudnicke
So I'm a complete idiot when it comes to using BAT files or scripting. Does this sound like a good statement?

for /R (dunno what variable to put here) IN (*.PDF) DO move /y *.PDF\

I understand that /R causes it to scan all the sub directories below where the FOR command is launched. Bu I'm unclear on what variable it needs.
--
I did have a sig, but I had to remove it because my political views were too 'wrong' for some users on DSLr.


Ken
Premium,MVM
join:2003-06-16
Markle, IN
reply to rudnicke
I never learned much about batch files, but I do have one that is close to what you are trying to do. This file scans all the sub-directories below where the file is placed and makes a copy of every .vtx file. It doesn't move the file anywhere new though, it leaves it in the same directory. It also names the new file dx80.vtx. I think you just need to change the last portion for your needs.

FOR /R %%a IN ("*.vtx") DO copy "%%a" "%%~dpa%%~na.dx80.vtx"
 


rudnicke
Premium
join:2004-10-23
Rantoul, IL
kudos:4
So here is what I came up with, but it doesnt' seem to work. Can someone tell me what I'm missing?

FOR /R %%a IN ("*.PDF") DO move /y *.*
--
I did have a sig, but I had to remove it because my political views were too 'wrong' for some users on DSLr.


Carpie

join:2012-10-19
united state
kudos:5
Looks to me like you are missing the destination for the files you want to move. Where do you want to move them?

For example. If you wanted to move a file called moveme.txt that was located at the root C:\ to a folder called heyimmoved located at C:\heyimmoved, then you could use:

1) move c:\moveme.txt c:\heyimmoved
2) move moveme.txt heyimmoved (assuming you were starting at c:\)

(Using the full pathnames like the first option is your best bet since it doesn't matter what folder you are starting in)

An example of moving it back would be:

1) move c:\heyimmoved\moveme.txt c:\
2) move moveme.txt .. (assuming you are in the heyimmoved folder)

Chances are you don't need the /y parameter on move either unless you are working in an older version of DOS
--
Absolution -- MSV: 6/6 0/6H -- HoF: 4/6 -- ToES: 4/4 -- ToT: 12/12 -- SoO: 4/14F 1/14
Pride and Ego -- MSV: 6/6 1/6H -- HoF: 6/6 -- ToES: 4/4 -- ToT: 11/12 -- SoO: 3/14F */14


rudnicke
Premium
join:2004-10-23
Rantoul, IL
kudos:4
reply to rudnicke
I"m not sure I have the correct format for this command. I'm launching the FOR command in the directory that I just created on a server.

EX:

cd X:\ENDDAY\BR01
md .\%Year%%Month%%Day%
cd %Year%%Month%%Day%

This creates a folder based on the date. I end up with a folder X:\ENDDAY\BR01\09302013. I then CD in to that directory so I'm then at X:\ENDDAY\BR01\09232013 which is where I now initiate the FOR command.

THe syntax I tried using is: FOR /R %%a IN ("*.PDF") DO move Q:\01\*.PDF.

I'm trying to get this command to move all files with the PDF extension, located n the Q:\01\ to X:\ENDDAY\BR01\09302013.

As I hae it now, it just sits there in a loop saying the file cannot be found.
--
I did have a sig, but I had to remove it because my political views were too 'wrong' for some users on DSLr.

dave
Premium,MVM
join:2000-05-04
not in ohio
kudos:8
Reviews:
·Verizon FiOS

1 edit
'FOR' executes the command for one file at a time, and if the command is to make any sense, it needs to mention the file it has just been told to work on.

And furthermore, the command should not mention "all PDFs" again.

Now I look back at your original post and at the above, I see that you're somehow expecting move to work with one file specification. 'move' needs to be given a source specification (possibly wildcarded) and a destination specification (which needs to be just a directory, if there are multiple source files).

Something like this (not tested) should do it.

for /r %%a in ("*.pdf") do move %%~nxa q:\01


The %%~nxa gives you just the name and extension of the current file. I think that's what you want, right?


rudnicke
Premium
join:2004-10-23
Rantoul, IL
kudos:4
Thanks for the update. I tried a test BAT file running the line above, but I think I may still be missing something. I put PDF files in the Q:\01\, but it did not scour the sub directories under Q:\01 to find any file to move to the directory where I initiated the command.
--
I did have a sig, but I had to remove it because my political views were too 'wrong' for some users on DSLr.

dave
Premium,MVM
join:2000-05-04
not in ohio
kudos:8
Reviews:
·Verizon FiOS

1 edit
That's because the 'for /r' command operates from where you are, and the 'move' command moves things to the second argument.

I wrote Q:\01 because that's what you wrote before: your incorrect code appeared to be moving PDFs from the subtree where you were cd'd to, into a fixed directory. In retrospect, I notice that you never gave any clear description of what you were trying to do, and I never asked, but instead guessed based on your incorrect examples.

I think you need to spend some time understanding basic command concepts.