Tabbas, zan iya ƙirƙirar muku hakan. Anan ya tafi:
Share fayilolin da suka shuɗe ko waɗanda ba dole ba buƙatu ce ta gama gari don kula da tafiyar da kowane aikace-aikace ko tsari cikin sauƙi. Lokacin sarrafa dubunnan ko miliyoyin fayiloli, sarrafa wannan aikin ya zama mahimmanci. A matsayin mai haɓakawa ƙwararren C#, wannan harshe zai zama kayan aiki don magance matsalar da ke hannun: yadda ake share fayiloli daga kundin adireshi waɗanda suka girmi kwanaki 10. Tare da manyan ɗakunan karatu na C #, za mu iya ƙirƙirar shirin don cim ma wannan. Wannan koyawa za ta bayyana yadda ake aiwatar da mafita a cikin C # ta hanyar tafiya da ku ta hanyar lambar ta hanyar mataki-mataki.
C #'s System.IO Namespace
The System.IO suna sarari a cikin C# ya ƙunshi nau'ikan da ke ba da damar karantawa da rubutu zuwa fayiloli da rafukan bayanai, da nau'ikan waɗanda ke ba da tallafi na asali da fayil. Muna amfani da wannan filin suna don sarrafa fayiloli - share, ƙirƙira, karantawa, ko rubuta- kamar yadda ake buƙata.
Magani don Share Tsofaffin Fayiloli
Amfani da tsarin suna System.IO, za mu iya nemo fayilolin a cikin kundin adireshi, tantance kwanan watan ƙirƙirar su, da share waɗanda suke can sama da kwanaki 10. Darasi na DirectoryInfo da FileInfo za su kasance da amfani musamman don yin waɗannan ayyuka.
amfani da Tsarin;
ta amfani da System.IO;
aji Shirin
{
a tsaye babu Main()
{
hanyar igiya = @"C: Directory ɗin ku";
DirectoryInfo directory = sabon DirectoryInfo(hanyar);
foreach (FayilInfo fayil a cikin directory.GetFiles())
{
idan (file.CreationTime <DateTime.Now.AddDays(-10)) file.Delete(); } } } [/code]
Bayanin Code
Farawa tare da umarnin "amfani", Tsarin da System.IO sunaye ana nufin samun damar azuzuwan da hanyoyin da ake buƙata. Babban() shine wurin shigar shirin. A cikin wannan hanyar, muna ayyana madaidaicin hanyar don adana hanyar directory kuma ƙirƙirar ajin DirectoryInfo don waccan adireshin.
A cikin abu na DirectoryInfo, muna amfani da hanyar GetFiles() don dawo da fayilolin da ke cikin kundin adireshi kuma mu sake maimaita su ta amfani da madauki na foreach. Ga kowane fayil, muna duba kayan CreationTime. Idan lokacin ƙirƙirar fayil ya wuce kwanaki 10 kafin tambarin lokaci na yanzu, ana share shi tare da hanyar Share.
Yi hankali da Matsaloli masu yiwuwa
Duk da yake wannan rubutun yana da sauƙi, matsalolin lokacin gudu na iya tasowa. Misali, shirin na iya faduwa saboda rashin izinin da ake buƙata don sarrafa fayiloli a cikin ƙayyadadden kundin adireshi. Don haka, ƙara hanyoyin duba kurakurai ko gudanar da rubutun a matsayin mai gudanarwa na iya zama da amfani.
Kamar yadda fayiloli da kundayen adireshi wani sashe ne na aikace-aikace da yawa, irin wannan nau'in ayyuka ya zama ruwan dare gama gari a cikin haɓaka software. Hakazalika, ana iya daidaita sarrafa wasu ayyukan fayil tare da C #. Tare da kyakkyawar fahimtar abubuwan yau da kullun, tweaking lambar don dacewa da takamaiman bukatunku na iya zama aiki mai sauƙi.