-1

I am looking to copy all text files on the C drive, but the program needs to avoid text files that are part of the system, and only copy the text files that have been created by the user.

Is there a built in way to do this, or do I need to get creative? If so, how would you go about it? I would like to keep it within batch and not involve powershell or anything like that.

I thought about using creation dates to determine whether or not a file is a system file, but that didn't work all the way.

Carl P.
  • 11
  • 4
  • If you do a dir /q , are all the NT AUTHORITY\SYSTEM files the system files you are talking about or do they include the ones which are BUILTIN\Administrators – cup Feb 27 '17 at 08:23

1 Answers1

0

You can generate a list of all systemfiles using the dir command. So

dir /b /as > %USERPROFILE%\excluded_Files.txt

Would generate a list of the systemfiles from that directory.

Using xcopy as described here you can now copy all files from one directory to another excluding the systemfiles.

The xcopy command should be something like this:

xcopy C:\firstDirectory\*.txt C:\secondDirectory /EXCLUDE:%USERPROFILE%\excluded_Files.txt

Edit

So your code that is there would copy all rtf and txt files from the whole C drive to Drive D folder E.

A batch-file using my method would look like this:

@echo off
cd /d C:\
dir /b /as /s > %USERPROFILE%\excluded_Files.txt
xcopy C:\*.rtf D:\E /EXCLUDE:%USERPROFILE%\excluded_Files.txt /s
xcopy C:\*.txt D:\E /EXCLUDE:%USERPROFILE%\excluded_Files.txt /s

Explanation:
@echo off supresses redundant output of the commands that would be displayed before execution.
cd /d C:\ changes the current execution directory to the root of the C drive. /d is added for potential drive change.
dir /b /as /s > %USERPROFILE%\excluded_Files.txt redirects the output of the dir command into a file in your userprofile (Usually C:\Users\yourUserName). The switch /b will only show the filenames and not size, creation date etc. /as will only list system files and /s makes the dir command work recursively through all directories.
xcopy C:\*.rtf D:\E /EXCLUDE:%USERPROFILE%\excluded_Files.txt /s will copy all rtf files from C:\ to D:\E and exclude all files from the list previously created (that will contain all system txt and rtf files (as well as others)). /s makes xcopy work recursively as for dir.
Next line is a copy of the same with txt files.

Community
  • 1
  • 1
geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
  • So for the code: `for /R "C:\" %%G in (*.rtf *.txt) do copy "%%G" "D:\E"` how would that work out? Probably a basic question but I'm just learning batch right now. – Carl P. Feb 27 '17 at 09:10
  • Glad that I could help! – geisterfurz007 Feb 27 '17 at 18:00
  • Hey, Geister, I just ran the code and I noticed that some System32/SysWOW64 text files are copied, are these not considered system files / are only some files system files in System32? – Carl P. Feb 27 '17 at 20:53
  • I can only use what is given by the help of the commands. Run `dir /?` in a command prompt. It will tell the same as I did. I am no Windows system/file expert at all... – geisterfurz007 Feb 27 '17 at 20:57