Molecular devices with high switching performance and/or the perfect spin filtering effect have always been the pursuit with the development of molecular electronics. Here, by using the nonequilibrium Green’s function method in combination with the density functional theory, the switching performance and spin filtering properties of dimethyldihydropyrene (DHP)/cyclophanediene (CPD) photoswitchable molecule connected by carbon atomic chains (CACs) to two zigzag graphene nanoribbon electrodes have been theoretically investigated. The results show that DHP is more conductive than CPD and therefore an evident switching effect is demonstrated, and the switching ratio (RON/OFF) can reach 4.5 x 103. It is further revealed that the RON/OFF of DHP /CPD closely depends on the length of CACs. More specifically, the RON/OFF values of DHP /CPD with odd-numbered CACs are larger than those with even-numbered CACs. More interestingly, a high or even perfect spin filtering effect can be obtained in these investigated DHP /CPD single-molecule devices. Our study is helpful for future design of single-molecule switches and spin filters and provides a way to optimize their performance by means of varying the length of bridging CACs.