[batch] move folders and files

nono313 Posted messages 196 Status Membre -  
nono313 Posted messages 196 Status Membre -
Hello,
I am a beginner in batch
I wrote a script that allows me to move everything in one folder to another folder.
move ".\subfolder\"* .\

The problem is that it only moves files and not the folders that are in /subfolder/
Configuration: Windows Vista

6 réponses

nono313 Posted messages 196 Status Membre 27
 
up
0
jfr1784 Posted messages 73 Status Membre 27
 
Hello Nono313

Try with:

move "source_folder_name" "destination_folder_name"

while omitting the asterisk intended to replace the file names but don't forget to include the " if your folder names contain spaces.

Have a good evening.

JF
0
nono313 Posted messages 196 Status Membre 27
 
Thank you for your response
I tried
move ".\Complete Downloads\" .\

and
move ".\Complete Downloads\" ".\"

and it still doesn't work
0
jfr1784 Posted messages 73 Status Membre 27
 
Re-hello

Oops, I forgot, the "move" command only transfers one directory at a time... you would need to loop through the names of the directories and files located in the "Complete Downloads" directory

However, you can use the "xcopy" command which will allow you to transfer everything in one go

If I understand what you are trying to do, it's to move an entire directory tree up one level. If that's the case, from the destination directory, run the command

xcopy /F /E "Complete Downloads\*"

(help xcopy will allow you to see the available options with this command)

/F will display the files and directories copied
/E will also copy empty directories

This, however, has the downside that you will temporarily need more space on the disk.

The directory structure in the "Complete Downloads" directory can then be deleted with the command

rd /S /Q "Complete Downloads"

There you go, I hope I was able to help you.

Have a good evening.

JF
0
nono313 Posted messages 196 Status Membre 27
 
Thank you for your reply, I can now copy the files and folders.
The problem is that the rd command also deletes the "Completed downloads" folder instead of just emptying it.
0
jfr1784 Posted messages 73 Status Membre 27
 
So the simplest way is to create a small batch file with the following code:

xcopy /F /E %1
rd /S /Q %1
md %1

You can name it "up.bat" and simply run it with

up "Complete downloads"

It will also allow you to go up other directories since %1 replaces the parameter you give to the up command.

Have a good evening.

JF
0
nono313 Posted messages 196 Status Membre 27
 
Thank you very much, it works well but...
goto start :start up "Downloads complete" timeout /T 60 goto start

with this code, the batch file closes by itself after moving the files instead of waiting 60 seconds and repeating the loop.
0