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.
Related
I know the filename, say myfile.pdf. But I do not know its location because my web application created it temporarily. When the user disconnect from the application then I want this file to be deleted. So how to search and delete the file?
del path\filename /s
e.g.
del c:\test\h.bat /s
Will delete h.bat in any sub folders from the test directory.
To search and delete on an entire drive: -
del c:\test.bat /s
The S switch deletes all specified files from all subdirectories.
You can delete files by using this command.
rm [filename]
i am using windows 7 32 bit ultimate, i want to know if anyone can use cmd or command prompt (move command) and fix this problem :
i have folder (mypro) on drive (C) and i also have same folder on (D) drive. now when i use cmd like the following it says "access denied"
c:> move mypro d:\
access denied
c:>
c:> move/y mypro d:\
access denied
c:>
c:> move/-y mypro d:\
access denied
c:>
also i i run with administration rights but its not working again
In case there are no subfolders in your c:\mypro\ -folder, try this:
move /y mypro\* d:\mypro\
In case you've got subfolders the solution seems to require a BAT-file.
If you need that, let me know.
I prefer using Xcopy and then remove the directory on C,
I think you have a directory "Mypro" on C partition, and you have the same folder "Mypro" on partition D:
You can try this solution:
First: copy entire directory within sub-directory using Xcopy like this
C:>xcopy /s /e /y MyPro d:\MyPro
/s: Copies directories and subdirectories except for empty ones.
/e: Copies directories and subdirectories, including empty ones.
/y: Suppresses prompting to confirm you want to overwrite an
existing destination file.
Second: remove the entire directory "MyPro" on partition C while you move all files/folders
C:>rmdir /s mypro
/s: Removes all directories and files in the specified directory
in addition to the directory itself.
Please let me know if your problem doesn't solve.
C:\>xcopy /s /e /y MyPro d:\MyPro
C:\>rmdir /s mypro
I want to delete all files and folders in the directory, without deleting the root directory.
For eg: My tree structure is C:\app\temp.
The temp folder has a dist_timestamp folder and the dist folder has few files and folders. I would like to delete starting from dist folder, however if I am going to delete a dist_timestamp folder tomorrow, I cannot regenerate the timestamp the folder was created on. So technically, I would like to remove all folders under temp, without deleting temp.
I used rmdir /q C:\app\temp, and this seems to remove the temp folder also. Please help.
You can use this,
REM Opening the folder.
CD C:\app\
REM Deleting temp folder with all subdirectories and files.
RMDIR /S /Q temp
REM Creating new temp folder.
MKDIR temp
/S - Force deleting of read-only files.
/Q - Quite mode, do not ask if it ok to remove a directory tree with /S
This works:
pushd "C:\app\temp" && (rd /s /q . 2>nul&popd)
Im trying to make a batch file that will copy all new files and folders from a source folder to an network directory. All the new subdirectories and new files should be copied (backup).
My code:
xcopy "C:\Source" "T:\Backup" /d/i/s/q
(/d for only new files, /i because source is a dir, /s for all the subdirs and files, /q just to supress the copy text)
Source contains both subdirectories and files (.txt).
The first run it copies Everything as it should. When I add a new .txt file to one of the existing subdirectories and run it again I get the message:
"An error occured when the file The directory is not empty. was being created.
The folder "T:\Backup" could not be created.
0 files copied.
(Translated from Swedish so not 100% original)
The thing is when I try this command to a local source like e.g. "C:\test" and do the same procedure it works.
Anyone who can understand why this doesn't work for the network drive?
Should I try Another command such as robocopy?
Skip xcopy and use robocopy with the /E flag instead. It's built into all recent versions of Windows. Free download for XP.
Example:
robocopy c:\source T:\backup /E
That will copy all the files in the "source" folder to the "backup" folder that haven't been copied already.
And if you don't want to have the output shown on the console (equivalent to the /Q option in xcopy):
robocopy c:\source T:\backup /E /LOG:nul
Robocopy must be better because it should create directories with the \E switch. No overwrites for files, just adds a file with extra letters or extension <> command. Still must defrag.
XCOPY "DRIVE LETTER:\windows.old\USERS" "\computername\D\NAME\" /D /E /C /R /I /K /Y /f
I am trying to copy a folder from one directory to another in the CMD in Windows 7.
I have found commands for copying individual files:
copy test.txt "C:\NewLocation"
Which works fine. However trying something like this:
copy "C:\Test" "C:\NewLocation"
doesn't work. It wants to take the contents of the directory and move them over. Is there anyway to copy the FOLDER and move it as opposed to the entire directory contents?
Thanks.
Use xcopy instead of copy:
xcopy "C:\Test" "C:\NewLocation" /s /e
source
You can't "copy" folders, but you can "move" them:
move c:\test c:\newlocation
You could use xcopy:
xcopy /S C:\Test C:\NewLocation