Pages

Saturday, June 23, 2012

Copying Files in Order Using the MS-DOS FOR Command

 

Scenario: Copying pictures from a Windows 7 computer to a Nix X13A Digital Frame. In Windows 7, I arranged the pictures in the order I wanted using Windows Explorer, by name like Photo 001.jpg, Photo 002.jpg, etc. Then I copied them to the Digital Frame and discovered they were out of sequence.

Figuring Out What Happened: The Nix site says that to ensure photos in an exact sequence, you should load them one-by-one which implies it uses the date stamp of the time in the device (digital frame) to determine order.

Solution: There are many solutions, but this is what I did to copy each file one-by-one, in order automatically using the FOR loop command.

1. Open a command prompt, e.g. by typing cmd.exe in the Start menu. (Or use the winkey + R which opens a Run window and then type in cmd.)

2. In the Windows Command Processor window, navigate to the directory where the pictures are kept on your computer.

3. Type the following DOS command and check the output to make sure that the files are listed in the order you want.

for /r %i in (*) do echo %i 


You can customize the command. For example, if you want only files starting with “Photo”, you can modify the command as shown below.

for /r %i in (Photo*) do echo %i 


4. Assuming the Digital Frame is connected and appears on D:\ and the folder you want to copy to on the device is “Some Folder” then this command will do the task of copying the files in the order you want.

for /r %i in (Photo*) do copy "%i" "D:\Some Folder"\. 


Note: The ordering of files in Windows Explorer when you sort by file name can differ from the ordering in a Windows Command Processor window using “dir * /O=N” which orders by name which is the default. In particular, this difference occurs when you use use the bulk rename feature in Windows Explorer. The bulk rename leaves you with files that have parentheses in the name and the sorting gets interesting. For example “Test File (10).jpg” comes before “Test File (2).jpg” in the DOS output but not in Windows Explorer. So beware.


No comments:

Post a Comment

All comments go through a moderation process. Even though it may not look like the comment was accepted, it probably was. Check back in a day if you asked a question. Thanks!