| 1. |
Solve : Xcopy - certain file extensions only .pdf? |
|
Answer» I've set up the xcopy command in a batch so i can schedule it to run overnight - I'm useless with DOS so I just set up a basic xcopy as all I NEED is to move files from one folder to another (see below). It works brilliantly but all i want to move is the .pdf timetables Are all pdf files timetables? If not, is there a way to distinguish a pdf timetabe from other pdf files. You may have to narrow the wildcard search. Cheers sidewinder, I thought (more hoped) it would be something simple like my coding!! I've tested it on a random sample but it didn't work, I tried it without the *.pdf and it copied all the files from 1 folder to another no problem. The pdf files are all named either s1234 or p12345 if this helps (1234 etc being a random 4/5 digit number) All timetables are the only pdf's in the folders cheers for the help I knew i'd need it.Quote I've tested it on a random sample but it didn't work How didn't it work? Error messages? Incorrect results? When you ran it without the *.pdf filter were any pdf files copied? The *.pdf indicates to the machine you only want pdf files. If nothing was copied, I can only think that there are no pdf files in Y:\mi\WebPublishing\Students. Is this code part of a larger group of code? No error messages - when I ran it without the *.pdf it copied everything in the folder!! This is where I'm having trouble it should all run smoothly but it refuses for some reason to pick up the pdf's!! An example of what's listed in the folder is: d20index 4KB HTML Document shrink 1KB GIF Image p13629 11KB Adobe Acrobat Document (this being the timetables) I don't need all the html etc just the pdf's. There is no larger code is like you stated at the begining very simple/concise!! CURIOUSER and curiouser! I don't mean to sound condescending, but does that p13629 file actually have a pdf extension? Will you post a directory listing of that directory? I'm looking to see the file extension not the file type. Quote This is where I'm having trouble it should all run smoothly You're absolutely right. This is pretty simple stuff. in xcopy if copying a file from one directory to another where the file does not already exist, it will prompt the user for input: press F if object is file and D if directory, its frustrating Run your batch and tap the F key a few times, it will copy one .pdf for each F if my guess is correct. You can output your command to a log file to see the prompts sent to your batch when troubleshooting. example: XCOPY /F "\\servername\c$\temp\*.pdf " "\\servername\d\mydir\" >> log.txt 2>&1Hi All DOS commands respond to the /? option. Always worth a go XCOPY /? lists a tremendous range, including :- /L to tell you what it would have done - can save the embarrassment of copying C:\Windows\... to a floppy disc etc !!! /I which may overcome any ambiguity over whether the destination is a file or a Directory. Regards Alan Although NOT new to DOS, I'm new to this particular forum and I'm reading it with great interest. Thank you guys for a great forum. Now my question: In the above posts I see the XCopy line with double backslashes in it ( \\ ). What's that all about? I'm used to using more precise path statements. By the way, I save many hours every week by doing things with batch files rather than trying some other method. I use a batch file in my Startup folder to remove as many temp (garbage) files as I can that were generated the day before. But I've never used that double backslash. Help? The Shadow Hey Shadow, Check out the lower part of this link for some explanations. http://en.wikipedia.org/wiki/Path_(computing) hope that helps NTWell, today I guess I'm batting a big fat Zero, because that link told me nothing about double backslashes. A quick explanation would have sufficed. Oh well, I'm sorry I asked a question in someone else's thread. My bad! Hey Shadow The double backslash just indicates the directory on a different server/pc; if you're copying local to local then you dont need them. XCOPY is most useful from one machine to another, otherwise just use COPY. I'm a little new to this forum as well, at least as far as posting so maybe I ADD a step in there that wasn't asked for. Sorry for the confusion.Hey, the confusion was all mine. I do remember \\ being used to express a folder on a Server or other PC on a network, but I didn't see how that applied to this thread. I don't do networking, so that really eluded me, till you explained it. Again, my apologies, and thanks for the clarification. I really appreciate yous guys! Quote from: r0mad on September 26, 2008, 02:55:25 PM in xcopy if copying a file from one directory to another where the file does not already exist, it will prompt the user for input: press F if object is file and D if directory, its frustrating Hi r0mad, I had the same problem until I found the "/I" switch, which has the effect that "If destination does not exist and copying more than one file, assumes that destination must be a directory". Here's my code suggestion below. It uses relative paths instead opf absolute paths, and assumes you want to copy pdf files in the 'targetDirectory" and it's subdirectories to a temporary location. Code: [Select]xcopy .\targetDirectory\*.pdf .\myTempDir /S /F /-Y /I Hope this helps. With the myriad and various switches available to XCOPY, you can do almost anything you want to with it. I keep "My Documents" backed up to my second HD with this simple one-line batch file which I run manually, every few days. I could also put that backup batch file in my startup folder for a free backup every time I reboot my PC. xcopy "C:\Documents and Settings\MyUserName\My Documents\*.*" "D:\My Documents\" /s /y /H /R /D I use similar batch files to back up all my email files and other select folders. I've been using xcopy now for more years than I really want to admit to, and I'm constantly finding new uses for it. Here's a list of the xcopy switches: ************************************************ Copies files and directory trees. XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W] [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U] [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/EXCLUDE:file1[+file2][+file3]...] source Specifies the file(s) to copy. destination Specifies the location and/or name of new files. /A Copies only files with the archive attribute set, doesn't change the attribute. /M Copies only files with the archive attribute set, turns off the archive attribute. /D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time. /EXCLUDE:file1[+file2][+file3]... Specifies a list of files containing strings. Each string should be in a separate line in the files. When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied. For example, specifying a string like \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively. /P Prompts you before creating each destination file. /S Copies directories and subdirectories except empty ones. /E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. /V Verifies each new file. /W Prompts you to press a key before copying. /C Continues copying even if errors occur. /I If destination does not exist and copying more than one file, assumes that destination must be a directory. /Q Does not display file names while copying. /F Displays full source and destination file names while copying. /L Displays files that would be copied. /G Allows the copying of encrypted files to destination that does not support encryption. /H Copies hidden and system files also. /R Overwrites read-only files. /T Creates directory structure, but does not copy files. Does not include empty directories or subdirectories. /T /E includes empty directories and subdirectories. /U Copies only files that already exist in destination. /K Copies attributes. NORMAL Xcopy will reset read-only attributes. /N Copies using the generated short names. /O Copies file ownership and ACL information. /X Copies file audit settings (implies /O). /Y Suppresses prompting to confirm you want to overwrite an existing destination file. /-Y Causes prompting to confirm you want to overwrite an existing destination file. /Z Copies networked files in restartable mode. The switch /Y may be preset in the COPYCMD environment variable. This may be overridden with /-Y on the command line. ***************************************** So you see, with that long list of switches, xcopy can and does do many different chores. For me xcopy replaces at least a half dozen programs and is much easier to set up and use. I hope this all helps someone.......somewhere. Cheers Mates! the Shadow |
|