主頁 > 知識庫 > Windows 8技巧:windows 8文件 文件夾管理[文件以及文件夾操作]

Windows 8技巧:windows 8文件 文件夾管理[文件以及文件夾操作]

熱門標簽:金昆地圖標注是干什么的 高德地圖標注地點更改電話號碼 世界地圖標注國家怎么畫 外呼系統(tǒng)打哪顯哪 行政區(qū)劃地圖標注app 口碑好的電話機器人費用 沈陽高頻外呼防封系統(tǒng)哪家好 南寧銷售外呼系統(tǒng)廠家 溫嶺地圖標注

     在本文中我們將學(xué)習(xí)win 8中的文件以及文件夾的各種操作。

  在本文中文件操作主要是講述:刪除文件/移動文件/復(fù)制文件/重命名文件

  文件夾操作分為:讀取文件夾/創(chuàng)建文件夾/刪除文件夾/重命名文件夾

  首先貼出所有的Xaml代碼文件部分:

復(fù)制代碼
代碼如下:

Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
!--顯示區(qū)-->
TextBlock HorizontalAlignment="Left" Margin="137,42,0,0" TextWrapping="Wrap" Text="文件名:"
VerticalAlignment="Top" Height="23" Width="43"/>
TextBox HorizontalAlignment="Left" Margin="185,33,0,0" TextWrapping="Wrap"
Text="test.txt" VerticalAlignment="Top" Width="121" Name="tbFileName"/>
TextBox HorizontalAlignment="Left" Margin="457,33,0,0" TextWrapping="Wrap"
Text="默認需要添加的文件內(nèi)容" VerticalAlignment="Top" Width="431" Name="tbContent"/>
TextBlock HorizontalAlignment="Left" Margin="396,42,0,0" TextWrapping="Wrap" Text="文件內(nèi)容:"
VerticalAlignment="Top" Height="23" Width="61"/>
TextBlock HorizontalAlignment="Left" Margin="127,163,0,0" TextWrapping="Wrap" Text="提示:"
VerticalAlignment="Top" Height="23" Width="761" Name="tb_show"/>
!--刪除文件 移動文件 復(fù)制文件 重命名文件-->
Button Content="創(chuàng)建并寫入文件" HorizontalAlignment="Left" Margin="127,99,0,0"
Name="btnCreateFile" VerticalAlignment="Top" Click="btnCreateFile_Click"/>
Button Content="讀取string文件" HorizontalAlignment="Left" Margin="757,99,0,0"
x:Name="btnReadFile" VerticalAlignment="Top" Click="btnReadFile_Click"/>
Button Content="刪除文件" HorizontalAlignment="Left" Margin="127,223,0,0"
x:Name="btnDeleteFile" VerticalAlignment="Top" Click="btnDeleteFile_Click"/>
Button Content="移動文件" HorizontalAlignment="Left" Margin="320,223,0,0"
x:Name="btnMoveFile" VerticalAlignment="Top" Click="btnMoveFile_Click"/>
Button Content="復(fù)制文件" HorizontalAlignment="Left" Margin="560,223,0,0"
x:Name="btnCopyFile" VerticalAlignment="Top" Click="btnCopyFile_Click"/>
Button Content="重命名文件" HorizontalAlignment="Left" Margin="780,223,0,0"
x:Name="btnReNameFile" VerticalAlignment="Top" Click="btnReNameFile_Click"/>
!--讀取文件夾 創(chuàng)建文件夾 刪除文件夾 重命名文件夾-->
Button Content="讀取文件夾" HorizontalAlignment="Left" Margin="127,296,0,0"
VerticalAlignment="Top" Name="readFolder" Click="readFolder_Click"/>
Button Content="創(chuàng)建文件夾" HorizontalAlignment="Left" Margin="305,296,0,0"
VerticalAlignment="Top" x:Name="btnCreateFolder" Click="btnCreateFolder_Click"/>
Button Content="刪除文件夾" HorizontalAlignment="Left" Margin="545,296,0,0"
VerticalAlignment="Top" x:Name="btnDeleteFolder" Click="btnDeleteFolder_Click"/>
Button Content="重命名文件夾" HorizontalAlignment="Left" Margin="766,296,0,0"
VerticalAlignment="Top" x:Name="btnReNameFolder" Click="btnReNameFolder_Click"/>
/Grid>

  其次我們來看刪除文件/移動文件/復(fù)制文件/重命名文件的Cs代碼:

復(fù)制代碼
代碼如下:

private async void btnDeleteFile_Click(object sender, RoutedEventArgs e)
{
try
{
StorageFile sf = await storageFolder.GetFileAsync(this.tbFileName.Text.Trim());
await sf.DeleteAsync();
tb_show.Text = "提示:" + this.tbFileName.Text.Trim() + "文件刪除成功!";
}
catch (Exception ex)
{
tb_show.Text = "提示:未找到該文件,請先創(chuàng)建文件";
}
}/p> p> private async void btnMoveFile_Click(object sender, RoutedEventArgs e)
{
try
{
//將文件從文檔移動到音樂庫
StorageFile sf = await storageFolder.GetFileAsync(this.tbFileName.Text.Trim());
StorageFolder newfolder = KnownFolders.MusicLibrary;
await sf.MoveAsync(newfolder, "moveFile.txt", NameCollisionOption.ReplaceExisting);
tb_show.Text = "提示:“庫\\文檔\\" + this.tbFileName.Text.Trim() + "”文件移動到“庫\\音樂\\moveFile.txt”";
}
catch (Exception ex)
{
tb_show.Text = "提示:未找到該文件,請先創(chuàng)建文件";
}
}/p> p> private async void btnCopyFile_Click(object sender, RoutedEventArgs e)
{
try
{
StorageFile sf = await storageFolder.GetFileAsync(this.tbFileName.Text.Trim());
StorageFile storageFileCopy = await sf.CopyAsync(KnownFolders.DocumentsLibrary, "copyFile.txt",
NameCollisionOption.ReplaceExisting);
tb_show.Text = "提示:“庫\\文檔\\" + this.tbFileName.Text.Trim() + "”文件拷貝一份到“庫\\文檔\\copyFile.txt”";
}
catch (Exception ex)
{
tb_show.Text = "提示:未找到該文件,請先創(chuàng)建文件";
}
}/p> p> private async void btnReNameFile_Click(object sender, RoutedEventArgs e)
{
try
{
StorageFile sf = await storageFolder.GetFileAsync(this.tbFileName.Text.Trim());
await sf.RenameAsync("renameFile.txt", NameCollisionOption.ReplaceExisting);
tb_show.Text = "提示:“庫\\文檔\\" + this.tbFileName.Text.Trim() + "”文件重命名為“庫\\文檔\\renameFile.txt”";
}
catch (Exception ex)
{
tb_show.Text = "提示:未找到該文件,請先創(chuàng)建文件";
}
}

 最后我們來看文件夾操作讀取文件夾/創(chuàng)建文件夾/刪除文件夾/重命名文件夾的Cs代碼如下:

復(fù)制代碼
代碼如下:

private async void readFolder_Click(object sender, RoutedEventArgs e)
{
StorageFolder picfolder = KnownFolders.PicturesLibrary;
IReadOnlyListStorageFile> list = await picfolder.GetFilesAsync();
string picinfo = "圖片庫文件夾下文件名是:";
foreach (StorageFile item in list)
{
picinfo += item.Name + "+";
}
tb_show.Text = picinfo;
}/p> p> private async void btnCreateFolder_Click(object sender, RoutedEventArgs e)
{
try
{
StorageFolder picfolder = KnownFolders.PicturesLibrary;
await picfolder.CreateFolderAsync("NewMusic", CreationCollisionOption.ReplaceExisting);
tb_show.Text = "提示:“庫\\圖片\\”文件夾下新建“庫\\圖片\\NewMusic”文件夾";
}
catch (Exception ex)
{
tb_show.Text = "提示:未找到該文件夾,請先創(chuàng)建文件夾";
}
}/p> p> private async void btnDeleteFolder_Click(object sender, RoutedEventArgs e)
{
try
{
StorageFolder picfolder = KnownFolders.PicturesLibrary;
var newFolder = await picfolder.GetFolderAsync("NewMusic");
await newFolder.DeleteAsync();
tb_show.Text = "提示:“庫\\圖片\\”文件夾下刪除“庫\\圖片\\NewMusic”文件夾";
}
catch (Exception ex)
{
tb_show.Text = "提示:未找到該文件夾,請先創(chuàng)建文件夾";
}
}/p> p> private async void btnReNameFolder_Click(object sender, RoutedEventArgs e)
{
try
{
StorageFolder picfolder = KnownFolders.PicturesLibrary;
var newFolder = await picfolder.GetFolderAsync("NewMusic");
await newFolder.RenameAsync("New Picture");
tb_show.Text = "提示:“庫\\圖片\\”文件夾下重命名“庫\\圖片\\NewMusic”文件夾";
}
catch (Exception ex)
{
tb_show.Text = "提示:未找到該文件夾,請先創(chuàng)建文件夾";
}
}

  最后如需源碼請點擊 Win8File2_jb51net.rar 下載

標簽:撫順 沈陽 中衛(wèi) 石嘴山 中山 煙臺 防封 焦作

巨人網(wǎng)絡(luò)通訊聲明:本文標題《Windows 8技巧:windows 8文件 文件夾管理[文件以及文件夾操作]》,本文關(guān)鍵詞  Windows,技巧,windows,8文件,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Windows 8技巧:windows 8文件 文件夾管理[文件以及文件夾操作]》相關(guān)的同類信息!
  • 本頁收集關(guān)于Windows 8技巧:windows 8文件 文件夾管理[文件以及文件夾操作]的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章