Home>

We become indebted to.

1. I want to achieve
After allocating to the drive with the net use command, use the xcopy command to copy the one in the specified folder of storage to the folder of the server to be released.
I was able to copy it, but after that, the process of deleting the entire folder contained in the file from the folder in the specified location of the storage did not go well, and I am struggling.

I tried using the del command, but what other commands can be used to delete the entire folder contained in the file?

I would appreciate it if you could tell me. I look forward to working with you.

2. Conditions
The drive assigned to the specified folder of the storage is the A drive, and the drive assigned to the folder of the release server is the B drive.

3. Batch file statement created by myself
echo echo

Connect to a specified location in storage with rem net use
net use A: (Enter your full path here) (Enter your password here)/user: (Enter your domain name here) \ (Enter your ID here)

rem net use Connect to a folder on the server to release
net use B: (Enter your full path here) (Enter your password here)/user: (Enter your domain name here) \ (Enter your ID here)

Copy the folder in the specified location of rem storage to the specified folder on the server to be released.
xcopy A: \ (folder name in the specified storage location) B: \ (folder name specified on the server)/I/S/E/Y/Q

If the rem copy is successful, delete the entire folder contained in the file from the folder in the specified location of the storage.
del/q A: \ (folder name) \

Disconnect rem A drive
net use A:/delete

Disconnect rem B drive
net use B:/delete

pause

  • Answer # 1

    From the comment in the "Request for addition/correction to question" column [2020/11/14 22:48]:

    For example, if the folder name is "FOLDER", do you delete the entire A: \ FOLDER? Or do you delete the files and folders under A: \ FOLDER?
    ⇒ "Are you sure you want to delete the files and folders under A: \ FOLDER?"

    If you delete the entire "A: \ FOLDER"RMDIRUsing commandsRMDIR/Q/S A: \ FOLDERIt's a one-shot, but it's a little troublesome to leave the specified original folder. The files directly under the specified folder areDELDelete with the command, and the folders (including files) under itRMDIRThe following is an example of a batch file (* .cmd) that is deleted one by one with a command.TARGETDIRSpecify the PATH of the folder in the variable. In this exampleS: \ WORK \ FOLDER \It is said.

    set TARGETDIR = S: \ WORK \ FOLDER \
    if ""% TARGETDIR% "" ==" "" "goto END
    rem Delete only the files directly under the specified folder
    del/q% TARGETDIR% *
    Delete per rem folder
    for/D %% F in (% TARGETDIR% *) do (
        rmdir/q/s %% F
    )
    : END

    *TARGETDIRVariable value is empty (""), From under the current directory when executing the batch fileAll folders and files will be deleted.Therefore, in the above example, if it is an empty string, it is skipped. Please understand the contents and use with caution when using it as a reference.