1.

Solve : Creating a current date directory then moving files to the directory?

Answer»

I have syntax to create a current date directory yet not sure how to move text  files within the newly created directory.

The code successfully makes the directory but the move statement fails it sees the parameter as "" for fldr

Code: [Select]echo on

REM Title: EXP_BFS_DATA batch command
REM Title: Transfer of nightly BFS data export to a dated folder


REM Navigate to server BFS_Backup folder
REM Create a backup folder with today's date.

p:
CD p:\BFS_Backup
FOR /F "tokens=1-5 delims=/ " %%d IN ("%date%") DO MKDIR %%g-%%e-%%f

REM Move nighlty BFS data export text files to dated folder

MOVE p:\BFS_Backup\*.TXT c:\BFS_Backup\??? - Unsure what to put here
FOR /F "tokens=1-5 delims=/ " %%d IN ("%date%") DO set d=%%g-%%e-%%f

md c:\BFS_Backup\%d%
MOVE p:\BFS_Backup\*.txt c:\BFS_Backup\%d%\
Awesome Reno!! 

If I want to take just one step further and do IF EXISTS and IF NOT EXISTS for the directory how can I adjust the script?

Would the IF NOT EXISTS then the md command otherwise MOVE?  I am trying to come to a place that the command doesn't error on creating a current date folder if the current date folder (for some reason) existed.



Code: [Select]echo on

REM Title: EXP_BFS_DATA batch command
REM Title: Transfer of nightly BFS data export to a dated folder


REM Navigate to server BFS_Backup folder
REM Create a backup folder with today's date.

p:
CD p:\BFS_Backup
FOR /F "tokens=1-5 delims=/ " %%d IN ("%date%") DO SET fldr=%%g-%%e-%%f
MD p:\BFS_Backup\%fldr%

REM Move nighlty BFS data export text files to dated folder

MOVE "p:\BFS_Backup\*.txt" "p:\BFS_Backup\%fldr%"easy

Code: [Select]if not exist p:\BFS_Backup\%fldr%\ MD p:\BFS_Backup\%fldr%

from the help file if /?
Code: [Select]The ELSE clause must occur on the same line as the command after the IF.  For
example:

    IF EXIST filename. (
        del filename.
    ) ELSE (
        echo filename. missing.
    )Reno...

Last thing...if I want to log all the activity (like echo) into a log file is there any syntax for that? 

> to clear file and echo sth to it
>> to add line into it

ex.
Code: [Select]echo TEXT >file.txtperhaps that is not what I want...

Output needed only for errors

So something like

IF ERROR = 1
 THEN error.txt
  ELSE END

to output errors use this:
Quote

del file.txt 2>error.txt
Sorry for sounding dumb but what does file.txt represent?

Delete file.txt produces error.txt?

Why the delete?

Quote from: JTS on June 03, 2009, 10:42:58 AM
Sorry for sounding dumb but what does file.txt represent?

Delete file.txt produces error.txt?

Why the delete?


Dev just used delete as an example...if you used mkdir Foldername 2>error.txt, it would echo any errors to error.txtThanks all for the help....appreciate it..



Discussion

No Comment Found