Delete all file/directories from each subfolder windows shell - windows

I have a question, I have the following paths:
C:\Vendita\folder1\files and subfolders
C:\Vendita\folder3\files and subfolders
C:\Vendita\folder3\files and subfolders
I want to delete (using win shell commands), for each subfolder (C:\Vendita\folder1,C:\Vendita\folder2,C:\Vendita\folder2...) all files and subfolders, but keeping folder1, folder2 ecc...
I try this:
for %D in (C:\Vendita\) do del *.* /s /q
but it deletes all files and keeps all subfolders.
Can you explain me what is wrong?
Thank you

Why don't you use rmdir? Your command only removes files with a certain filename.

Related

How to exclude a filetype when using the REN command in cmd?

I have a batch script which moves all the files from one folder to another and then renames them all to .jpg, however my .bat file itself gets renamed in the process because it sits in the destination folder. I need to exclude it from getting renamed.
Also, does the ren command exclude items in subfolders by default? I only want items in the destination folder renamed, not items in its subfolders.
#echo off
xcopy "C:\Folder1" "C:\Folder2"
cd "C:\Folder2" && ren *.* *.jpg
pause

How to delete files in folders and all subfolders which contain specific string in file name?

I have folder where I have tons of other subfolders and each of them contains files like
original_file1.jpg
original_file1_t1.jpg
original_file2.jpg
original_file2_t1.jpg
and so on
I would like to remove all of them from within Windows command prompt and I tried that with
del /s *_t1.*
But it is only removing files within folder that I am currently.
How to do this with code that will check every folder within this location?
The structure of folders looks like this:
Main_folder/album_1/original_file1_t1.jpg
Main_folder/album_2/original_file1_t1.jpg
and so on
Ok, I am so sorry for posting this thread but I found the solution.
When You are in your main folder just use
del /s /q *_t1.jpg

how to delete folders but not files in a folder by cmd

How to delete folders but not files in a folder by cmd?
Such as, there is a direcory:
c:\image\1.png
c:\image\2.png
c:\image\3.png
c:\image\*.png
c:\image\folder1\*.png
c:\image\folder2\*.png
....
Now I don't know how to delete all the folders (and subfiles) folder1, folder2...", only remain the files 1.png, 2.png, 3.png, 4.png ...
for /d %F in (c:\image\*) do rd /s /q "%F"
Double up the percents if used within a batch file

Delete Files with Windows Command Prompt

There is a shared folder in my D drive as works (D:\works). I need to delete all the files in that folder and sub folders except word and excel files in there. how can i do this ?
You could do something similar to what this guy's done: http://www.codesingh.com/2009/08/using-robocopy-to-delete-old-files-from.html
Something like this should work:
mkdir D:\_tempDelete
robocopy D:\works D:\_tempDelete /e /MOVE /XF *.xls* *.doc*
rmdir D:\_tempDelete /s /q
Provided you have permissions to create and delete folders on D:. Otherwise you could just move the files somewhere on your local drive and delete them from there.

Batch to move files in a folder to another folder?

I want to create a batch file that moves all the files in this directory to its father directory. Like for example if I have a directory " Something " that contains files :
...New Folder/Something
And I want to move the files in " Something " to New folder.
Is there such a command?
Thanks a bunch :)
Presuming you're talking about Windows batch files, move *.* ..\ should do the trick.
Edit: For example, if you opened cmd, you could input:
cd C:\New Folder\Something
move *.* ..\
which would move all files in C:\New Folder\Something into its 'father' directory.
It is possible only if you don't have subdirectories, because move doesn't walk the subdirectories.
You can use xcopy with /E, however it will not delete the copied files and directories. Then you should use del ., but to delete the subdirectories you should call rd for each one, and that is not possible in batch files.

Resources