Thursday, October 19, 2017

Do your batch scripts expect directory changes across volumes?

I have a batch script that copies some files around, invokes a PowerShell script to transform them, and deletes extra copies of the originals. The script resides in the same folder as the source files, executing a cd to an output folder before running the script that will change them. That way, the alteration and eventual deletion will apply to the copied files and not the only originals. I keep the source folder in my Dropbox, which on the machine where I wrote the script is on the C drive, but on this computer is on D, separate from the rest of my profile. When the script tried to cd to the output folder (under my profile, on C), it didn't actually change the current drive or the current drive's current directory because the /d flag was not specified. It then went on to transform and delete the originals. Fortunately, since it was in Dropbox, restoring them was easy, but I would still have preferred that it didn't happen. In the future, I'll be careful that my batch scripts are prepared for cross-volume operations.

No comments:

Post a Comment